Skip to main content

DynamicTypeBuilder

Struct DynamicTypeBuilder 

Source
pub struct DynamicTypeBuilder { /* private fields */ }
Expand description

XTypes §7.5.4 DynamicTypeBuilder.

Implementations§

Source§

impl DynamicTypeBuilder

Source

pub fn descriptor(&self) -> &TypeDescriptor

Current descriptor (read-only view).

Source

pub fn set_descriptor( &mut self, descriptor: TypeDescriptor, ) -> Result<(), DynamicError>

Sets the descriptor anew (spec §7.5.4.1 SetDescriptor) — only allowed before build().

§Errors

PreconditionNotMet if build() was already called.

Source

pub fn add_member( &mut self, descriptor: MemberDescriptor, ) -> Result<(), DynamicError>

Adds a member (spec §7.5.4.1.2 AddMember).

Validates immediately:

  • Unique name among the existing members.
  • Unique id (only when composite XCDR2-capable).
  • The member type is consistent.
  • The kind allows members.

index is set automatically if the caller leaves it at 0, otherwise respected.

§Errors

BuilderConflict on a dup name/id, IllegalOperation if the kind carries no members.

Source

pub fn add_member_resolved( &mut self, descriptor: MemberDescriptor, member_type: DynamicType, ) -> Result<(), DynamicError>

Adds a member whose type is a fully-resolved DynamicType instead of being (shallowly) reconstructed from descriptor.member_type. Used by the TypeObject → DynamicType bridge to attach a recursively-resolved nested composite (struct/union/enum) member type — add_member would otherwise rebuild it from the member’s shallow TypeDescriptor and lose the nested members. Runs the same validity checks as [add_member].

§Errors

PreconditionNotMet after build(), IllegalOperation on a non-composite, Inconsistent/Builder on a malformed or duplicate member.

Source

pub fn add_struct_member( &mut self, name: impl Into<String>, id: MemberId, ty: TypeDescriptor, ) -> Result<(), DynamicError>

Convenience wrapper for structs.

§Errors

See [add_member].

Source

pub fn build(&self) -> Result<DynamicType, DynamicError>

Spec §7.5.4.1.1 Build — finalizes the builder.

Validations:

  • all member descriptors consistent
  • inheritance cycle via names
  • union: discriminator + at least 1 case
  • unique labels in a union
§Errors

BuilderConflict / Inconsistent.

Trait Implementations§

Source§

impl Debug for DynamicTypeBuilder

Source§

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

Formats the value using the given formatter. 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.