pub struct DynamicTypeBuilder { /* private fields */ }Expand description
XTypes §7.5.4 DynamicTypeBuilder.
Implementations§
Source§impl DynamicTypeBuilder
impl DynamicTypeBuilder
Sourcepub fn descriptor(&self) -> &TypeDescriptor
pub fn descriptor(&self) -> &TypeDescriptor
Current descriptor (read-only view).
Sourcepub fn set_descriptor(
&mut self,
descriptor: TypeDescriptor,
) -> Result<(), DynamicError>
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.
Sourcepub fn add_member(
&mut self,
descriptor: MemberDescriptor,
) -> Result<(), DynamicError>
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.
Sourcepub fn add_member_resolved(
&mut self,
descriptor: MemberDescriptor,
member_type: DynamicType,
) -> Result<(), DynamicError>
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.
Sourcepub fn add_struct_member(
&mut self,
name: impl Into<String>,
id: MemberId,
ty: TypeDescriptor,
) -> Result<(), DynamicError>
pub fn add_struct_member( &mut self, name: impl Into<String>, id: MemberId, ty: TypeDescriptor, ) -> Result<(), DynamicError>
Sourcepub fn build(&self) -> Result<DynamicType, DynamicError>
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.