//!
//! //! Generate typescript type declarations from rust types //!
//! //! //! //! ## Why? //! When building a web application in rust, data structures have to be shared between backend and frontend. //! Using this library, you can easily generate TypeScript bindings to your rust structs & enums so that you can keep your //! types in one place. //! //! ts-rs might also come in handy when working with webassembly. //! //! ## How? //! ts-rs exposes a single trait, `TS`. Using a derive macro, you can implement this interface for your types. //! Then, you can use this trait to obtain the TypeScript bindings. //! We recommend doing this in your tests. //! [See the example](https://github.com/Aleph-Alpha/ts-rs/blob/main/example/src/lib.rs) and [the docs](https://docs.rs/ts-rs/latest/ts_rs/). //! //! ## Get started //! ```toml //! [dependencies] //! ts-rs = "12.0" //! ``` //! //! ```rust //! #[derive(ts_rs::TS)] //! #[ts(export)] //! struct User { //! user_id: i32, //! first_name: String, //! last_name: String, //! } //! ``` //! //! When running `cargo test` or `cargo test export_bindings`, the following TypeScript type will be exported to `bindings/User.ts`: //! //! ```ts //! export type User = { user_id: number, first_name: string, last_name: string, }; //! ``` //! //! ## Features //! - generate type declarations from rust structs //! - generate union declarations from rust enums //! - works with generic types //! - compatible with serde //! - generate necessary imports when exporting to multiple files //! - precise control over generated types //! //! If there's a type you're dealing with which doesn't implement `TS`, you can use either //! `#[ts(as = "..")]` or `#[ts(type = "..")]`, enable the appropriate cargo feature, or open a PR. //! //! ## Configuration //! When using `#[ts(export)]` on a type, `ts-rs` generates a test which writes the bindings for it to disk.\ //! The following environment variables may be set to configure *how* and *where*: //! | Variable | Description | Default | //! |--------------------------|---------------------------------------------------------------------|--------------| //! | `TS_RS_EXPORT_DIR` | Base directory into which bindings will be exported | `./bindings` | //! | `TS_RS_IMPORT_EXTENSION` | File extension used in `import` statements | *none* | //! | `TS_RS_LARGE_INT` | Binding used for large integer types (`i64`, `u64`, `i128`, `u128`) | `bigint` | //! //! We recommend putting this configuration in the project's [config.toml](https://doc.rust-lang.org/cargo/reference/config.html#env) to make it persistent: //! ```toml //! #