Skip to main content

StructDef

Struct StructDef 

Source
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: u16

Number of data words in the struct section (from CGR). Used by TypeScript codegen for correct wire format offsets.

§pointer_words: u16

Number of pointer words in the struct section (from CGR).

§discriminant_count: u16

Discriminant count (number of union members).

§discriminant_offset: u32

Offset 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

Source

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.

Source

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.

Source

pub fn is_pure_union(&self) -> bool

True if this struct is a pure union (has_union and no non-union fields).

Source

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.

Trait Implementations§

Source§

impl Debug for StructDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for StructDef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for StructDef

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,