Skip to main content

FromReflect

Trait FromReflect 

pub trait FromReflect: Sized + Reflect {
    // Required method
    fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Self>;

    // Provided method
    fn take_from_reflect(
        reflect: Box<dyn PartialReflect>,
    ) -> Result<Self, Box<dyn PartialReflect>> { ... }
}
Expand description

A trait that enables types to be dynamically constructed from reflected data.

It’s recommended to use the derive macro rather than manually implementing this trait.

FromReflect allows dynamic proxy types, like DynamicStruct, to be used to generate their concrete counterparts. It can also be used to partially or fully clone a type (depending on whether it has ignored fields or not).

In some cases, this trait may even be required. Deriving Reflect on an enum requires all its fields to implement FromReflect. Additionally, some complex types like Vec<T> require that their element types implement this trait. The reason for such requirements is that some operations require new data to be constructed, such as swapping to a new variant or pushing data to a homogeneous list.

See the crate-level documentation to see how this trait can be used.

Required Methods§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Self>

Constructs a concrete instance of Self from a reflected value.

Provided Methods§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails.

This method is more efficient than using from_reflect for cases where the given value is likely a boxed instance of Self (i.e. Box<Self>) rather than a boxed dynamic type (e.g. DynamicStruct, DynamicList, etc.).

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.

Implementations on Foreign Types§

§

impl FromReflect for &'static str

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<&'static str>

§

impl FromReflect for &'static Location<'static>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<&'static Location<'static>>

§

impl FromReflect for Cow<'static, str>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<Cow<'static, str>>

§

impl FromReflect for SocketAddr

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<SocketAddr>

§

impl FromReflect for bool

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<bool>

§

impl FromReflect for char

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<char>

§

impl FromReflect for f32

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<f32>

§

impl FromReflect for f64

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<f64>

§

impl FromReflect for i8

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<i8>

§

impl FromReflect for i16

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<i16>

§

impl FromReflect for i32

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<i32>

§

impl FromReflect for i64

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<i64>

§

impl FromReflect for i128

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<i128>

§

impl FromReflect for isize

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<isize>

§

impl FromReflect for u8

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<u8>

§

impl FromReflect for u16

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<u16>

§

impl FromReflect for u32

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<u32>

§

impl FromReflect for u64

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<u64>

§

impl FromReflect for u128

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<u128>

§

impl FromReflect for ()

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<()>

§

impl FromReflect for usize

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<usize>

§

impl FromReflect for String

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<String>

§

impl FromReflect for TypeId

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<TypeId>

§

impl FromReflect for NonZero<i8>

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<NonZero<i8>>

§

impl FromReflect for NonZero<i16>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<i16>>

§

impl FromReflect for NonZero<i32>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<i32>>

§

impl FromReflect for NonZero<i64>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<i64>>

§

impl FromReflect for NonZero<i128>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<i128>>

§

impl FromReflect for NonZero<isize>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<isize>>

§

impl FromReflect for NonZero<u8>

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<NonZero<u8>>

§

impl FromReflect for NonZero<u16>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<u16>>

§

impl FromReflect for NonZero<u32>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<u32>>

§

impl FromReflect for NonZero<u64>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<u64>>

§

impl FromReflect for NonZero<u128>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<u128>>

§

impl FromReflect for NonZero<usize>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<NonZero<usize>>

§

impl FromReflect for RangeFull

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<RangeFull>

§

impl FromReflect for AtomicBool

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicBool>

§

impl FromReflect for AtomicI8

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicI8>

§

impl FromReflect for AtomicI16

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicI16>

§

impl FromReflect for AtomicI32

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicI32>

§

impl FromReflect for AtomicI64

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicI64>

§

impl FromReflect for AtomicIsize

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicIsize>

§

impl FromReflect for AtomicU8

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicU8>

§

impl FromReflect for AtomicU16

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicU16>

§

impl FromReflect for AtomicU32

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicU32>

§

impl FromReflect for AtomicU64

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicU64>

§

impl FromReflect for AtomicUsize

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<AtomicUsize>

§

impl FromReflect for Duration

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Duration>

§

impl FromReflect for CuDuration

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<CuDuration>

§

impl FromReflect for CuTimeRange

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<CuTimeRange>

§

impl FromReflect for Instant

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Instant>

§

impl FromReflect for OptionCuTime

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<OptionCuTime>

§

impl FromReflect for PartialCuTimeRange

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<PartialCuTimeRange>

§

impl FromReflect for Tov

§

fn from_reflect(__param0: &(dyn PartialReflect + 'static)) -> Option<Tov>

§

impl<A> FromReflect for (A,)
where A: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<(A,)>

§

impl<A, B> FromReflect for (A, B)
where A: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, B: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<(A, B)>

§

impl<A, B, C> FromReflect for (A, B, C)
where A: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, B: FromReflect + MaybeTyped + TypePath + GetTypeRegistration, C: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<(A, B, C)>

§

impl<A, B, C, D> FromReflect for (A, B, C, D)

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<(A, B, C, D)>

§

impl<A, B, C, D, E> FromReflect for (A, B, C, D, E)

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<(A, B, C, D, E)>

§

impl<A, B, C, D, E, F> FromReflect for (A, B, C, D, E, F)

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<(A, B, C, D, E, F)>

§

impl<A, B, C, D, E, F, G> FromReflect for (A, B, C, D, E, F, G)

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<(A, B, C, D, E, F, G)>

§

impl<A, B, C, D, E, F, G, H> FromReflect for (A, B, C, D, E, F, G, H)

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<(A, B, C, D, E, F, G, H)>

§

impl<A, B, C, D, E, F, G, H, I> FromReflect for (A, B, C, D, E, F, G, H, I)

§

impl<A, B, C, D, E, F, G, H, I, J> FromReflect for (A, B, C, D, E, F, G, H, I, J)

§

impl<A, B, C, D, E, F, G, H, I, J, K> FromReflect for (A, B, C, D, E, F, G, H, I, J, K)

§

impl<A, B, C, D, E, F, G, H, I, J, K, L> FromReflect for (A, B, C, D, E, F, G, H, I, J, K, L)

§

impl<K, V> FromReflect for BTreeMap<K, V>
where K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord, V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<BTreeMap<K, V>>

§

impl<K, V, S> FromReflect for HashMap<K, V, S>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<HashMap<K, V, S>>

§

impl<T> FromReflect for Cow<'static, [T]>
where T: FromReflect + MaybeTyped + Clone + TypePath + GetTypeRegistration,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<Cow<'static, [T]>>

§

impl<T> FromReflect for Bound<T>
where T: Clone + Send + Sync + TypePath, Bound<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Bound<T>>

§

impl<T> FromReflect for Option<T>
where Option<T>: Any + Send + Sync, T: TypePath + FromReflect + MaybeTyped + RegisterForReflection,

§

fn from_reflect(__param0: &(dyn PartialReflect + 'static)) -> Option<Option<T>>

§

impl<T> FromReflect for BinaryHeap<T>
where T: Clone + TypePath, BinaryHeap<T>: Any + Send + Sync,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<BinaryHeap<T>>

§

impl<T> FromReflect for BTreeSet<T>
where T: Ord + Eq + Clone + Send + Sync + TypePath, BTreeSet<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<BTreeSet<T>>

§

impl<T> FromReflect for VecDeque<T>
where T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<VecDeque<T>>

§

impl<T> FromReflect for Arc<T>
where T: Send + Sync + TypePath + ?Sized, Arc<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Arc<T>>

§

impl<T> FromReflect for Vec<T>
where T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Vec<T>>

§

impl<T> FromReflect for Saturating<T>
where T: Clone + Send + Sync + TypePath, Saturating<T>: Any + Send + Sync,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<Saturating<T>>

§

impl<T> FromReflect for Wrapping<T>
where T: Clone + Send + Sync + TypePath, Wrapping<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Wrapping<T>>

§

impl<T> FromReflect for Range<T>
where T: Clone + Send + Sync + TypePath, Range<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Range<T>>

§

impl<T> FromReflect for RangeFrom<T>
where T: Clone + Send + Sync + TypePath, RangeFrom<T>: Any + Send + Sync,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<RangeFrom<T>>

§

impl<T> FromReflect for RangeInclusive<T>
where T: Clone + Send + Sync + TypePath, RangeInclusive<T>: Any + Send + Sync,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<RangeInclusive<T>>

§

impl<T> FromReflect for RangeTo<T>
where T: Clone + Send + Sync + TypePath, RangeTo<T>: Any + Send + Sync,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<RangeTo<T>>

§

impl<T> FromReflect for RangeToInclusive<T>
where T: Clone + Send + Sync + TypePath, RangeToInclusive<T>: Any + Send + Sync,

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<RangeToInclusive<T>>

§

impl<T, E> FromReflect for Result<T, E>
where Result<T, E>: Any + Send + Sync, T: TypePath + FromReflect + MaybeTyped + RegisterForReflection, E: TypePath + FromReflect + MaybeTyped + RegisterForReflection,

§

fn from_reflect( __param0: &(dyn PartialReflect + 'static), ) -> Option<Result<T, E>>

§

impl<T, const N: usize> FromReflect for [T; N]
where T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,

§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<[T; N]>

§

impl<V, S> FromReflect for HashSet<V, S>

§

fn from_reflect( reflect: &(dyn PartialReflect + 'static), ) -> Option<HashSet<V, S>>

Implementors§