Expand description
§Postcard Bindgen
This crate allows automatically generating javascript bindings to serialize javascript objects to postcard format and vice versa.
§Example
This example shows how to generate a npm
package out of the rust
structures. A new folder with the package name will be created. A
javascript file and typescript typings as well as a package.json
will be placed in it.
#[derive(Serialize, PostcardBindings)]
struct A(u8);
#[derive(Serialize, PostcardBindings)]
struct B {
a: u8
}
#[derive(Serialize, PostcardBindings)]
enum C {
A,
B(u8),
C(A, B),
D { a: &'static str, b: B },
}
fn main() {
build_package(
std::env::current_dir().unwrap().as_path(),
PackageInfo {
name: "test-bindings".into(),
version: "0.1.0".try_into().unwrap(),
},
GenerationSettings::enable_all(),
generate_bindings!(A, B, C),
)
.unwrap();
}
// JavaScript
import { serialize } form "test-bindings"
const c = {
tag: "C",
value: [
123,
{
a: 234
}
]
}
const bytes = serialize("C", c)
Modules§
- javascript
generating
- python
generating
Macros§
- generate_
bindings generating
- Macro to generate javascript and typescript binding strings which can be exported into files.
Structs§
- Package
Info generating
- Holds npm package info.
- Version
generating
- Defines a package version with major, minor, patch version numbers.
- Version
From StrError generating
- Error type that indicates that the supplied string is not a version formatted string.
Derive Macros§
- Postcard
Bindings - Macro to annotate structs or enums for which bindings should be generated.