Exports your types to other languages, currently supporting TypeScript.
Install
Add to your Cargo.toml
[]
= { = "0.2", = ["typescript"] }
Usage
Preparing your types
Decorate your types with the Burr derive macro.
use *;
;
;
Use the optional #[burr(mod)] attribute to assign your type to a module automatically.
use *;
// `Foo` will be automatically included in the specified module if not explicitly included during export
;
Exporting your types
In your build.rs or another binary, we can create an exporter and optionally configure it. The exporter and its components behave as builder patterns.
new
Add your types using modules to organize them. This module tree typically translates to the file structure being produced - with one file per module - but language constraits, features, or options can change this behavior.
.with_mod
Resolve type dependencies, which exports types your types depend on. They will be added to either the type's chosen module or the given default module. This step is unnecessary if you explicitly include all types needed to describe your data.
.resolve_exports
Export to one or more targets.
// outputs ./ts/common.ts and ./ts/bar.ts
.export?
// bundles all exported types into a single file
.export?
See these concepts in action in the example.
3rd-party types
For types that don't derive Burr, such as those from third-party crates, use an attribute to treat fields as another type:
;
Alternatively, you can register a 3rd-party type as a string name representing that type in the target language.
.export?
Desired features going forward
-
Replace panics with errors
-
tests
-
Rust target
- Support the same set of common features as TypeScript
- Generic types?