[−][src]Crate fastxdr
To generate Rust types from an XDR spec at build time, add fastxdr
to your
Cargo.toml
:
[build-dependencies]
# For the code generation
fastxdr = "1.0"
[dependencies]
# Required dependencies of the generated code
thiserror = "1.0"
bytes = "0.5"
And add a build.rs
at the crate root (not in src
!):
fn main() { // Tell Cargo to regenerate the types if the XDR spec changes println!("cargo:rerun-if-changed=xdr_spec.x"); // Read from xdr_spec.x, writing the generated code to out.rs std::fs::write( std::path::Path::new(std::env::var("OUT_DIR").unwrap().as_str()).join("out.rs"), fastxdr::Generator::default() .generate(include_str!("xdr_spec.x")) .unwrap(), ) .unwrap(); }
And then include the generated file in your application:
ⓘThis example deliberately fails to compile
// Where out.rs is the filename from above include!(concat!(env!("OUT_DIR"), "/out.rs")); use xdr::*;
To view the generated types, either export the generated types in your
application and use cargo doc
, or use the CLI to produce the generated
code directly for reading.
Modules
ast | |
impls |
Structs
Generator |
Constants
DEFAULT_DERIVE |
|
Type Definitions
Result |