bevy_reflect/
std_traits.rs

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