Macro ts_rs::export [−][src]
macro_rules! export { ($($(($decl:ident))? $($p:path),+ => $l:literal),* $(,)?) => { ... }; }
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.
#[derive(TS)] struct A; #[derive(TS)] struct B; #[derive(TS)] struct C; export! { A, B => "bindings/a.ts", C => "bindings/b.ts" }
When running cargo test, bindings for A, B and C will be exported to bindings/a.ts
and bindings/b.ts.
By default, export! always uses export type/interface.
If you wish, you can also use ambient declarations (declare type/interface):
#[derive(TS)] struct Declared; #[derive(TS)] struct Normal(Declared); export! { (declare) Declared => "bindings/declared.d.ts", Normal => "bindings/normal.ts" }
Since Declared is now an ambient declaration, bindings/normal.ts will not include an import
for bindings/declared.d.ts.