Rust target
Use the Rust target for Rust consumers that want serde-oriented generated model structures.
emit-targets: - type: Rust output-dir: "generated/rust" test-dir: "generated/rust/tests" import-path: "fixtures::model" enum-parsing: "case-insensitive" protocol-scaffolds: "compile-only" native-serialization: "serde"| Option | Why it matters |
|---|---|
output-dir | Where generated Rust source is written. |
test-dir | Where generated Rust tests are written. |
import-path | Import path used by generated tests. |
enum-parsing | Controls whether enum parsing is case-sensitive or case-insensitive. |
protocol-scaffolds | Emits compile-only test scaffolds for generated protocols. |
native-serialization | "serde" emits feature-gated Serialize/Deserialize impls; "none" opts out. Omission keeps the default cfg-gated serde surface for compatibility. |
Generated Rust surfaces include serde-oriented model structures, from_json/to_json and from_yaml/to_yaml helpers, provider wire mapping, and optional case-insensitive enum parsing.
Typical usage shape
Section titled “Typical usage shape”use fixtures::model::{FixtureRoot, LoadContext, SaveContext};
let root = FixtureRoot::from_json(json_text, &LoadContext::default())?;let saved = root.to_json(&SaveContext::default())?;The from_yaml and to_yaml helpers provide the same round-trip against YAML. JSON and YAML helpers return Result, so callers propagate serde errors with ?.
Choose enum-parsing deliberately. Default behavior is case-sensitive unless configured otherwise.
native-serialization: "serde" emits #[cfg(feature = "serde")] implementations for generated models and polymorphic kind enums. Those impls delegate through Typra’s canonical load_from_value and to_value paths instead of field-by-field derives, so serde interop preserves discriminator dispatch, field names, optional omission, typed records, and open-discriminator fallback payloads.