bevy_reflect/
std_traits.rs

1use crate::{FromType, Reflect};
2
3/// A struct used to provide the default value of a type.
4///
5/// A [`ReflectDefault`] for type `T` can be obtained via [`FromType::from_type`].
6#[derive(Clone)]
7pub struct ReflectDefault {
8    default: fn() -> Box<dyn Reflect>,
9}
10
11impl ReflectDefault {
12    pub fn default(&self) -> Box<dyn Reflect> {
13        (self.default)()
14    }
15}
16
17impl<T: Reflect + Default> FromType<T> for ReflectDefault {
18    fn from_type() -> Self {
19        ReflectDefault {
20            default: || Box::<T>::default(),
21        }
22    }
23}