pub trait PartialReflectExt {
Show 19 methods
// Required methods
fn try_map_get(
&self,
key: &(dyn PartialReflect + 'static),
) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>;
fn try_remove_boxed(
&mut self,
key: Box<dyn PartialReflect>,
) -> Result<Option<Box<dyn PartialReflect>>, InteropError>;
fn convert_to_0_indexed_key(&mut self);
fn from_reflect_or_clone(
reflect: &(dyn PartialReflect + 'static),
world: WorldAccessGuard<'_>,
) -> Result<Box<dyn PartialReflect>, InteropError>;
fn allocate(
boxed: Box<dyn Reflect>,
world: WorldAccessGuard<'_>,
) -> ReflectReference;
fn is_type(&self, crate_name: Option<&str>, type_ident: &str) -> bool;
fn expect_type(
&self,
crate_name: Option<&str>,
type_ident: &str,
) -> Result<(), InteropError>;
fn as_option(
&self,
) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>;
fn as_option_mut(
&mut self,
) -> Result<Option<&mut (dyn PartialReflect + 'static)>, InteropError>;
fn as_list(
&self,
) -> Result<impl Iterator<Item = &(dyn PartialReflect + 'static)>, InteropError>;
fn as_usize(&self) -> Result<usize, InteropError>;
fn set_as_list<F>(
&mut self,
other: Box<dyn PartialReflect>,
apply: F,
) -> Result<(), InteropError>
where F: Fn(&mut (dyn PartialReflect + 'static), &(dyn PartialReflect + 'static)) -> Result<(), InteropError>;
fn try_insert_boxed(
&mut self,
index: Box<dyn PartialReflect>,
value: Box<dyn PartialReflect>,
) -> Result<(), InteropError>;
fn try_push_boxed(
&mut self,
value: Box<dyn PartialReflect>,
) -> Result<(), InteropError>;
fn try_pop_boxed(&mut self) -> Result<Box<dyn PartialReflect>, InteropError>;
fn try_clear(&mut self) -> Result<(), InteropError>;
fn element_type_id(&self) -> Option<TypeId>;
fn key_type_id(&self) -> Option<TypeId>;
fn from_reflect(
reflect: &(dyn PartialReflect + 'static),
world: WorldAccessGuard<'_>,
) -> Result<Box<dyn Reflect>, InteropError>;
}Expand description
Extension trait for PartialReflect providing additional functionality for working with specific types.
Required Methods§
Sourcefn try_map_get(
&self,
key: &(dyn PartialReflect + 'static),
) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>
fn try_map_get( &self, key: &(dyn PartialReflect + 'static), ) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>
Try to get a reference to the given key in an underyling map, if the type is a map.
Sourcefn try_remove_boxed(
&mut self,
key: Box<dyn PartialReflect>,
) -> Result<Option<Box<dyn PartialReflect>>, InteropError>
fn try_remove_boxed( &mut self, key: Box<dyn PartialReflect>, ) -> Result<Option<Box<dyn PartialReflect>>, InteropError>
Try to remove the value at the given key, if the type supports removing with the given key.
Sourcefn convert_to_0_indexed_key(&mut self)
fn convert_to_0_indexed_key(&mut self)
Convert index keys to 0-indexed keys if this type is an index key.
Sourcefn from_reflect_or_clone(
reflect: &(dyn PartialReflect + 'static),
world: WorldAccessGuard<'_>,
) -> Result<Box<dyn PartialReflect>, InteropError>
fn from_reflect_or_clone( reflect: &(dyn PartialReflect + 'static), world: WorldAccessGuard<'_>, ) -> Result<Box<dyn PartialReflect>, InteropError>
Try to create a new instance of the concrete type from a possibly untyped reference.
Sourcefn allocate(
boxed: Box<dyn Reflect>,
world: WorldAccessGuard<'_>,
) -> ReflectReference
fn allocate( boxed: Box<dyn Reflect>, world: WorldAccessGuard<'_>, ) -> ReflectReference
Allocate a new boxed reflect reference from a boxed reflect.
Sourcefn is_type(&self, crate_name: Option<&str>, type_ident: &str) -> bool
fn is_type(&self, crate_name: Option<&str>, type_ident: &str) -> bool
Check if the represented type is from the given crate and has the given type identifier, returns false if not representing any type or if the type is not from the given crate or does not have the given type identifier.
Sourcefn expect_type(
&self,
crate_name: Option<&str>,
type_ident: &str,
) -> Result<(), InteropError>
fn expect_type( &self, crate_name: Option<&str>, type_ident: &str, ) -> Result<(), InteropError>
Equivalent to PartialReflectExt::is_type but returns an appropriate error if the type is not the expected one.
Sourcefn as_option(
&self,
) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>
fn as_option( &self, ) -> Result<Option<&(dyn PartialReflect + 'static)>, InteropError>
If the type is an option, returns either the inner value or None if the option is None. Errors if the type is not an option.
Sourcefn as_option_mut(
&mut self,
) -> Result<Option<&mut (dyn PartialReflect + 'static)>, InteropError>
fn as_option_mut( &mut self, ) -> Result<Option<&mut (dyn PartialReflect + 'static)>, InteropError>
Similar to PartialReflectExt::as_option but for mutable references.
Sourcefn as_list(
&self,
) -> Result<impl Iterator<Item = &(dyn PartialReflect + 'static)>, InteropError>
fn as_list( &self, ) -> Result<impl Iterator<Item = &(dyn PartialReflect + 'static)>, InteropError>
If the type is an iterable list-like type, returns an iterator over the elements.
Sourcefn as_usize(&self) -> Result<usize, InteropError>
fn as_usize(&self) -> Result<usize, InteropError>
If the type is a usize, returns the value as a usize otherwise throws a convenient error
Sourcefn set_as_list<F>(
&mut self,
other: Box<dyn PartialReflect>,
apply: F,
) -> Result<(), InteropError>where
F: Fn(&mut (dyn PartialReflect + 'static), &(dyn PartialReflect + 'static)) -> Result<(), InteropError>,
fn set_as_list<F>(
&mut self,
other: Box<dyn PartialReflect>,
apply: F,
) -> Result<(), InteropError>where
F: Fn(&mut (dyn PartialReflect + 'static), &(dyn PartialReflect + 'static)) -> Result<(), InteropError>,
If the type is an iterable list-like type, sets the elements of the list to the elements of the other list-like type. This acts as a set operation, so the left list will have the same length as the right list after this operation.
Sourcefn try_insert_boxed(
&mut self,
index: Box<dyn PartialReflect>,
value: Box<dyn PartialReflect>,
) -> Result<(), InteropError>
fn try_insert_boxed( &mut self, index: Box<dyn PartialReflect>, value: Box<dyn PartialReflect>, ) -> Result<(), InteropError>
Inserts into the type at the given key, if the type supports inserting with the given key
Sourcefn try_push_boxed(
&mut self,
value: Box<dyn PartialReflect>,
) -> Result<(), InteropError>
fn try_push_boxed( &mut self, value: Box<dyn PartialReflect>, ) -> Result<(), InteropError>
Tries to insert the given value into the type, if the type is a container type.
The insertion will happen at the natural end of the container.
For lists, this is the length of the list.
For sets, this will simply insert the value into the set.
For maps, there is no natural end, so the push will error out
Sourcefn try_pop_boxed(&mut self) -> Result<Box<dyn PartialReflect>, InteropError>
fn try_pop_boxed(&mut self) -> Result<Box<dyn PartialReflect>, InteropError>
If the type has a natural last element to pop, pops the last element and returns it as a boxed value.
Sourcefn try_clear(&mut self) -> Result<(), InteropError>
fn try_clear(&mut self) -> Result<(), InteropError>
If the type is a container type, empties the contents
Sourcefn element_type_id(&self) -> Option<TypeId>
fn element_type_id(&self) -> Option<TypeId>
If the type is a container type, returns the type id of the elements in the container. For maps, this is the type id of the values.
Sourcefn key_type_id(&self) -> Option<TypeId>
fn key_type_id(&self) -> Option<TypeId>
If the type is a container type, returns the type id of the keys in the container. For lists and arrays, this is the type id of usize. For maps, this is the type id of the keys.
Sourcefn from_reflect(
reflect: &(dyn PartialReflect + 'static),
world: WorldAccessGuard<'_>,
) -> Result<Box<dyn Reflect>, InteropError>
fn from_reflect( reflect: &(dyn PartialReflect + 'static), world: WorldAccessGuard<'_>, ) -> Result<Box<dyn Reflect>, InteropError>
Tries to construct the concrete underlying type from a possibly untyped reference
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.