pub struct ReflectConvert { /* private fields */ }Expand description
Provides a mechanism for converting values of one type to another.
This crate::type_registry::TypeData is associated with the type to be
converted into, not the type to be converted from. To convert a value,
use code like the following:
let reflect_convert = registry
.get_type_data::<ReflectConvert>(TypeId::of::<String>())
.unwrap();
let converted: String = *reflect_convert
.try_convert_from(Box::new(12345i32))
.unwrap()
.downcast::<String>()
.unwrap();Implementations§
Source§impl ReflectConvert
impl ReflectConvert
Sourcepub fn try_convert_from(
&self,
input: Box<dyn Reflect>,
) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
pub fn try_convert_from( &self, input: Box<dyn Reflect>, ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
Attempts to construct an instance of this type from the provided
input.
If the conversion fails, either because no conversion has been
registered from the type of input or because the conversion function
itself returned Err, the input value is returned as an error.
Sourcepub fn register_type_conversion<T, U, F>(&mut self, function: F)
pub fn register_type_conversion<T, U, F>(&mut self, function: F)
Adds a conversion function from the type T to this type.
If the conversion succeeds, the function should return the converted value. If the conversion fails, the function should return the original input value.
Trait Implementations§
Source§impl Clone for ReflectConvert
impl Clone for ReflectConvert
Source§impl Default for ReflectConvert
impl Default for ReflectConvert
Source§fn default() -> ReflectConvert
fn default() -> ReflectConvert
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ReflectConvert
impl !RefUnwindSafe for ReflectConvert
impl Send for ReflectConvert
impl Sync for ReflectConvert
impl Unpin for ReflectConvert
impl UnsafeUnpin for ReflectConvert
impl !UnwindSafe for ReflectConvert
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
Creates a type-erased clone of this value.