vexil-codegen-rust 0.4.3

Rust code generation backend for the Vexil schema compiler
Documentation

vexil-codegen-rust

Rust code generation backend for the Vexil schema compiler.

Takes a CompiledSchema from vexil-lang and emits Rust structs, enums, and Pack/Unpack implementations. Generated code depends on vexil-runtime for bit-level I/O.

Single file

use vexil_lang::compile;
use vexil_codegen_rust::generate;

let result = compile(source);
let compiled = result.compiled.expect("no errors");
let code: String = generate(&compiled)?;

Multi-file project

use vexil_lang::{compile_project, codegen::CodegenBackend};
use vexil_codegen_rust::RustBackend;

let project = compile_project(&root_source, &root_path, &loader)?;
let files: Vec<(PathBuf, String)> = RustBackend.generate_project(&project)?;
// one .rs file per schema + a mod.rs with re-exports

What gets generated

For each message: a struct with named fields, a Pack impl (encode), and an Unpack impl (decode). For enums: a Rust enum with TryFrom<u*>. For flags: a newtype over the backing integer with bitwise operations. For unions: a Rust enum with length-prefixed variants. For @delta messages: a stateful encoder/decoder pair that transmits field-level deltas.

License

Licensed under either of MIT or Apache-2.0 at your option.