Crate ts_rs[−][src]
Expand description
Generate TypeScript interface/type declarations from rust structs.
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 trait for
your types.
Then, you can use this trait to obtain the TypeScript bindings.
We recommend doing this in your tests. see the example
serde compatibility layer
With the serde-compat
feature enabled, ts-rs tries parsing serde attributes.
Please note that not all serde attributes are supported yet.
Macros
Expands to a test function which exports typescript bindings to one or multiple files when
running cargo test
.
If a type depends on an other type which is exported to a different file, an appropriate import
will be included.
If a file already exists, it will be overriden.
Missing parent directories of the file(s) will be created.
Paths are interpreted as being relative to the project root.
Like export!
but instead of creating a test function it executes the binding generation right here.
This may be useful if you’d like to run the binding generation in any other context than a test.
Traits
A type which can be represented in TypeScript.
Most of the time, you’d want to derive this trait instead of implementing it manually.
ts-rs comes with implementations for all numeric types, String
, Vec
, Option
and tuples.