pub struct StructDef {
pub name: String,
pub fields: Vec<FieldDef>,
pub has_union: bool,
pub domain_type: Option<String>,
pub origin_file: Option<String>,
pub data_words: u16,
pub pointer_words: u16,
pub discriminant_count: u16,
pub discriminant_offset: u32,
pub union_arms: Vec<UnionArm>,
}Fields§
§name: String§fields: Vec<FieldDef>§has_union: bool§domain_type: Option<String>Domain type path from $domainType annotation (e.g., “runtime::VersionResponse”).
When set, the generated client returns this type via FromCapnp::read_from().
origin_file: Option<String>Origin file stem for imported types (e.g., Some("streaming") for types from streaming.capnp).
None means the type is local to the service’s own schema file.
data_words: u16Number of data words in the struct section (from CGR). Used by TypeScript codegen for correct wire format offsets.
pointer_words: u16Number of pointer words in the struct section (from CGR).
discriminant_count: u16Discriminant count (number of union members).
discriminant_offset: u32Offset of the discriminant in the data section (in u16 units).
union_arms: Vec<UnionArm>Structured view of the union arms (when discriminant_count > 0).
Empty for non-union structs. Layered on top of the flat fields list:
fields still carries every union member for the wire-format/TS path,
while union_arms carries the per-arm payload shape (Void / single-type /
group) that Rust enum codegen consumes.
Implementations§
Source§impl StructDef
impl StructDef
Sourcepub fn non_union_fields(&self) -> impl Iterator<Item = &FieldDef>
pub fn non_union_fields(&self) -> impl Iterator<Item = &FieldDef>
Fields that are NOT union members (discriminant_value == 0xFFFF).
Use this for Rust codegen which should not generate get_*() / set_*()
calls for union members (Cap’n Proto Rust uses which() for those).
TypeScript codegen should use .fields directly since it needs all fields
including union members for wire format slot offsets and discriminant values.
Sourcepub fn union_fields(&self) -> impl Iterator<Item = &FieldDef>
pub fn union_fields(&self) -> impl Iterator<Item = &FieldDef>
Fields that ARE union members (discriminant_value != 0xFFFF).
These are the variant arms of a union within the struct.
Each has a distinct discriminant_value that identifies which arm is active.
Sourcepub fn is_pure_union(&self) -> bool
pub fn is_pure_union(&self) -> bool
True if this struct is a pure union (has_union and no non-union fields).
Sourcepub fn option_inner_type(&self) -> Option<&str>
pub fn option_inner_type(&self) -> Option<&str>
Returns the inner type name T if this struct is a valid Option<T> wrapper.
Validates that the struct is a pure union with exactly two variants:
none @0 :Void and some @1 :T.
This is more reliable than checking name.starts_with("Option") alone,
because it validates the actual structure rather than just the name.