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

    // Provided method
    fn take_from_reflect(
        reflect: Box<dyn Reflect>
    ) -> Result<Self, Box<dyn Reflect>> { ... }
}
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§

source

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

Constructs a concrete instance of Self from a reflected value.

Provided Methods§

source

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

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.).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FromReflect for &'static str

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for &'static Path

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for Cow<'static, str>

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for Cow<'static, Path>

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for bool
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for char
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for f32
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for f64
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for i8
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for i16
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for i32
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for i64
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for i128
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for isize
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for u8
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for u16
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for u32
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for u64
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for u128
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for ()

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for usize
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for String
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for RangeFull
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for Duration
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for OsString
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for PathBuf
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for Instant
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for Uuid
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroI8
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroI16
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroI32
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroI64
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroI128
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroIsize
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroU8
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroU16
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroU32
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroU64
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroU128
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl FromReflect for NonZeroUsize
where Self: Any + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl<T> FromReflect for HashSet<T>
where Self: Any + Send + Sync, T: TypePath + Hash + Eq + Clone + Send + Sync,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl<T, E> FromReflect for Result<T, E>
where Self: Any + Send + Sync, T: TypePath + Clone + Reflect + TypePath, E: TypePath + Clone + Reflect + TypePath,

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl<T: FromReflect + TypePath> FromReflect for Option<T>

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl<T: FromReflect + TypePath> FromReflect for VecDeque<T>

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

impl<T: FromReflect + TypePath> FromReflect for Vec<T>

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

source§

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

source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

Implementors§