Struct ReflectConvert
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§
§impl ReflectConvert
impl ReflectConvert
pub 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.
pub 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§
§impl Clone for ReflectConvert
impl Clone for ReflectConvert
§fn clone(&self) -> ReflectConvert
fn clone(&self) -> ReflectConvert
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Default for ReflectConvert
impl Default for ReflectConvert
§fn default() -> ReflectConvert
fn default() -> ReflectConvert
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ReflectConvert
impl !UnwindSafe for ReflectConvert
impl Freeze for ReflectConvert
impl Send for ReflectConvert
impl Sync for ReflectConvert
impl Unpin for ReflectConvert
impl UnsafeUnpin 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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more