mirror of
https://github.com/bevyengine/bevy
synced 2024-12-21 10:33:08 +00:00
efda7f3f9c
Takes the first two commits from #15375 and adds suggestions from this comment: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366968300 See #15375 for more reasoning/motivation. ## Rebasing (rerunning) ```rust git switch simpler-lint-fixes git reset --hard main cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "rustfmt" cargo clippy --workspace --all-targets --all-features --fix cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "clippy" git cherry-pick e6c0b94f6795222310fb812fa5c4512661fc7887 ```
31 lines
920 B
Rust
31 lines
920 B
Rust
/// An ergonomic abbreviation for [`Default::default()`] to make initializing structs easier.
|
|
///
|
|
/// This is especially helpful when combined with ["struct update syntax"](https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax).
|
|
/// ```
|
|
/// use bevy_utils::default;
|
|
///
|
|
/// #[derive(Default)]
|
|
/// struct Foo {
|
|
/// a: usize,
|
|
/// b: usize,
|
|
/// c: usize,
|
|
/// }
|
|
///
|
|
/// // Normally you would initialize a struct with defaults using "struct update syntax"
|
|
/// // combined with `Default::default()`. This example sets `Foo::bar` to 10 and the remaining
|
|
/// // values to their defaults.
|
|
/// let foo = Foo {
|
|
/// a: 10,
|
|
/// ..Default::default()
|
|
/// };
|
|
///
|
|
/// // But now you can do this, which is equivalent:
|
|
/// let foo = Foo {
|
|
/// a: 10,
|
|
/// ..default()
|
|
/// };
|
|
/// ```
|
|
#[inline]
|
|
pub fn default<T: Default>() -> T {
|
|
Default::default()
|
|
}
|