pub trait TypeInfoDynamic: Any {
// Required methods
fn get_dynamic(&self) -> &'static Type;
fn construct_struct(
&self,
args: Vec<Box<dyn Any>>,
) -> Result<Box<dyn Any>, RuntimeConstructError>;
fn construct_enum(
&self,
variant: &'static str,
args: Vec<Box<dyn Any>>,
) -> Result<Box<dyn Any>, RuntimeConstructError>;
fn field<'s>(
&'s self,
id: FieldId,
) -> Result<Unsizeable<'s>, FieldAccessError>;
fn field_mut<'s>(
&'s mut self,
id: FieldId,
) -> Result<UnsizeableMut<'s>, FieldAccessError>;
}Expand description
Object-safe version of TypeInfo
Additionally provides ability to construct type (if it’s not a enum without variants), and ability to borrow (both immutably and mutably) fields
Required Methods§
Sourcefn get_dynamic(&self) -> &'static Type
fn get_dynamic(&self) -> &'static Type
Get Type information for this type
Because it accepts reference to self, it can be called on [dyn] trait-objects
Sourcefn construct_struct(
&self,
args: Vec<Box<dyn Any>>,
) -> Result<Box<dyn Any>, RuntimeConstructError>
fn construct_struct( &self, args: Vec<Box<dyn Any>>, ) -> Result<Box<dyn Any>, RuntimeConstructError>
Constructs this type if it is a struct
Attempts to downcast passed arguments to type of fields. Multiple fields can be of same type, just make sure that order is preserved or you might get unexpected results
If called on enum type, RuntimeConstructError::NotStruct will be returned
Note: Arguments must be passed in same order as definition order of fields inside struct
Sourcefn construct_enum(
&self,
variant: &'static str,
args: Vec<Box<dyn Any>>,
) -> Result<Box<dyn Any>, RuntimeConstructError>
fn construct_enum( &self, variant: &'static str, args: Vec<Box<dyn Any>>, ) -> Result<Box<dyn Any>, RuntimeConstructError>
Constructs Self if it is enum
Attempts to downcast passed arguments as type of fields of requested variant, if there are any. List of required arguments is target variant-dependent, as well as their order
If variant is unit, no arguments will be required aside from variant
Note: Arguments must be passed in same order as definition order of fields inside of particular variant
Sourcefn field<'s>(&'s self, id: FieldId) -> Result<Unsizeable<'s>, FieldAccessError>
fn field<'s>(&'s self, id: FieldId) -> Result<Unsizeable<'s>, FieldAccessError>
Borrow immutably field inside this type
Type must not be a unit and id must be valid in terms of this type (present)
Returns Unsizeable, which can further be downcast to “nameable” type
Sourcefn field_mut<'s>(
&'s mut self,
id: FieldId,
) -> Result<UnsizeableMut<'s>, FieldAccessError>
fn field_mut<'s>( &'s mut self, id: FieldId, ) -> Result<UnsizeableMut<'s>, FieldAccessError>
Borrow mutably field inside this type
Same as [TypeInfo::field], except that returned “reference” is mutable