mirror of
https://github.com/bevyengine/bevy
synced 2024-12-20 10:03:07 +00:00
e71c4d2802
# Objective - fix new clippy lints before they get stable and break CI ## Solution - run `clippy --fix` to auto-fix machine-applicable lints - silence `clippy::should_implement_trait` for `fn HandleId::default<T: Asset>` ## Changes - always prefer `format!("{inline}")` over `format!("{}", not_inline)` - prefer `Box::default` (or `Box::<T>::default` if necessary) over `Box::new(T::default())`
23 lines
546 B
Rust
23 lines
546 B
Rust
use crate::{FromType, Reflect};
|
|
|
|
/// A struct used to provide the default value of a type.
|
|
///
|
|
/// A [`ReflectDefault`] for type `T` can be obtained via [`FromType::from_type`].
|
|
#[derive(Clone)]
|
|
pub struct ReflectDefault {
|
|
default: fn() -> Box<dyn Reflect>,
|
|
}
|
|
|
|
impl ReflectDefault {
|
|
pub fn default(&self) -> Box<dyn Reflect> {
|
|
(self.default)()
|
|
}
|
|
}
|
|
|
|
impl<T: Reflect + Default> FromType<T> for ReflectDefault {
|
|
fn from_type() -> Self {
|
|
ReflectDefault {
|
|
default: || Box::<T>::default(),
|
|
}
|
|
}
|
|
}
|