Camo

release version release date documentation

Documentation | Repository | Releases

Camo is a library for converting Rust type definitions into corresponding definitions in other languages.


Getting started

Add Camo as a dependency:

```sh

derive is included by default

cargo add camo

optionally add the typescript backend

cargo add camo --features typescript ```

Add the Camo derive macro to your type:

```rust use camo::Camo;

[derive(Camo)]

struct Book { title: String, author: String, page_count: usize, chapters: Vec, } ```

Use the generated Camo::camo() implementation:

rust fn main() { let book = Book::camo(); println!("{:?}", book); }

With the typescript feature enabled, create a TypeScript definition:

```rust use camo::{ /* ... */ typescript::Definition, };

/* ... */

fn main() {

/* ... */

let ty: Definition = book.into();

println!("{}", ty);
// interface Book {
//     title: string;
//     author: string;
//     page_count: number;
//     chapters: string[];
// }

} ```

See more examples here.

Features

| Feature | Default | Description | | ------------ | ------- | ----------- | | derive | Yes | Enables the [derive::Camo] derive macro. | | typescript | No | Enables the TypeScript backend, rooted in [typescript::Definition]. |

Crates

This project is composed of multiple crates in order to organize features.

Note that only camo is intended for general use.

| Crate | Description | | ----- | ----------- | | camo | This crate consolidates the subcrates, and is the only crate intended for general use. It exposes camo-core, and optionally exposes camo-derive and camo-typescript via feature switches. | | camo-core | This crate defines the AST at the core of camo, and is thus the foundation that the other crates build upon. | | camo-derive | This crate defines the derive macro Camo. | | camo-typescript | This crate implements a translation layer from the Camo AST to TypeScript definitions that can be written out directly, e.g. a file. |

License

camo is distributed under the terms of the MIT license. See LICENSE for details.