mirror of
https://github.com/bevyengine/bevy
synced 2025-01-02 00:08:53 +00:00
fd308571c4
# Objective - Shorten paths by removing unnecessary prefixes ## Solution - Remove the prefixes from many paths which do not need them. Finding the paths was done automatically using built-in refactoring tools in Jetbrains RustRover.
30 lines
916 B
Rust
30 lines
916 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()
|
|
}
|