tsync

License: MIT OR Apache-2.0

A utility to generate types for other typed languages.

Currently, only typescript is supported.

Install

There are two parts to this:

  1. The CLI tool:

    cargo install tsync

  2. The dependency for rust projects (to use the #[tsync] attribute; see usage below)

    ``` /// Cargo.toml

    tsync = "X.Y.Z" ```

Usage

Mark structs with #[tsync] as below:

```rust /// src/main.rs use tsync::tsync;

[tsync]

struct Book { name: String, chapters: Vec, user_reviews: Option> }

[tsync]

struct Chapter { title: String, pages: u32 } ```

Then use the CLI tool:

sh tsync -i src/main.rs -o types.d.ts

And voilĂ !

```ts /// types.d.ts

/* This file is generated and managed by tsync */

interface Book { name: string chapters: Array user_reviews: Array | undefined }

interface Chapter { title: string pages: number } ```

Note: globs don't recurse on all platforms so try double or triple globbing! sh tsync -i **/*.rs -o types.d.ts tsync -i **/**/*.rs -o types.d.ts tsync -i **/**/**/*.rs -o types.d.ts

Note: it might help to create multiple typing files for your project: sh tsync -i src/models/**/*.rs -o models.d.ts tsync -i src/api/**/*.rs -o api.d.ts

Docs

See tsync --help for more information.

Feel free to open tickets for support or feature requests.

License

This tool is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.