Expand description
Crate zerodds-idl-rust. Safety classification: STANDARD.
IDL4 → Rust code generator for ZeroDDS data types. Reads the IDL AST
from zerodds-idl and emits pub struct ... { ... } plus
impl zerodds_dcps::DdsType for ... plus the necessary
zerodds_cdr::CdrEncode/CdrDecode helpers.
Build-time tool — forbid(unsafe_code), std-only, no no_std use case.
§Layer position
Layer 3 (schema) — analogous to zerodds-idl-cpp/-csharp/-java/-ts,
but emits Rust code for the ZeroDDS-native stack.
§Public API
generate_rust_module— AST + options → Rust module code.RustGenOptions— codegen options.error::RustGenError— error family.
§What is emitted
Per IDL construct:
| IDL | Rust |
|---|---|
struct (final) | pub struct + impl DdsType with XCDR2-final wire |
struct (appendable) | with zerodds_cdr::struct_enc::encode_appendable |
struct (mutable) | with zerodds_cdr::struct_enc::MutableStructEncoder |
enum | pub enum #[repr(i32)] + from_wire + CdrEncode/Decode |
union | pub enum with variants per case |
typedef | pub type X = Y; |
module | pub mod m { ... } with nested definitions |
@key | encode_key_holder_be implementation |
@id(N) | member ID for mutable extensibility |
§Example
use zerodds_idl::config::ParserConfig;
use zerodds_idl_rust::{generate_rust_module, RustGenOptions};
let ast = zerodds_idl::parse(
"struct S { long x; long y; };",
&ParserConfig::default(),
)
.expect("parse");
let rust_src = generate_rust_module(&ast, &RustGenOptions::default()).expect("gen");
assert!(rust_src.contains("pub struct S"));
assert!(rust_src.contains("impl zerodds_dcps::DdsType for S"));Re-exports§
pub use emitter::RustGenOptions;pub use emitter::generate_rust_module;pub use error::Result;pub use error::RustGenError;
Modules§
- annotations
- Annotation processing:
@key,@id,@extensibility,@nested,@must_understand,@optional,@default. - bitset_
emit - IDL
bitset/bitmask→ Rust. - emitter
- Top-level emitter: AST → Rust string.
- enum_
emit - Emittiert IDL
enum→ Rustenum. - error
- Error family of the Rust codegen.
- struct_
emit - Emittiert
pub struct X { … }plusimpl DdsType for X { … }. - type_
identifier - F-TYPES-3 codegen: computes a spec-conformant
TypeIdentifier(XTypes 1.3 §7.3.4.2) for an IDL struct definition and emits it as a const expression in the DdsType impl. - type_
map - IDL type → Rust type mapping.
- typedef_
emit - Emittiert IDL
typedef→ Rustpub type X = Y;. - union_
emit - Emits IDL
union→ Rustenumwith a discriminator.