You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a `default()` shorthand for `Default::default()` ... because life is too short to constantly type `Default::default()`.
```rust
use bevy::prelude::*;
#[derive(Default)]
struct Foo {
bar: usize,
baz: usize,
}
// Normally you would do this:
let foo = Foo {
bar: 10,
..Default::default()
};
// But now you can do this:
let foo = Foo {
bar: 10,
..default()
};
```
The examples have been adapted to use `..default()`. I've left internal crates as-is for now because they don't pull in the bevy prelude, and the ergonomics of each case should be considered individually.
/// An ergonomic abbreviation for [`Default::default()`] to make initializing structs easier.
2
+
/// 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).
3
+
/// ```
4
+
/// use bevy_utils::default;
5
+
///
6
+
/// #[derive(Default)]
7
+
/// struct Foo {
8
+
/// a: usize,
9
+
/// b: usize,
10
+
/// c: usize,
11
+
/// }
12
+
///
13
+
/// // Normally you would initialize a struct with defaults using "struct update syntax"
14
+
/// // combined with `Default::default()`. This example sets `Foo::bar` to 10 and the remaining
15
+
/// // values to their defaults.
16
+
/// let foo = Foo {
17
+
/// a: 10,
18
+
/// ..Default::default()
19
+
/// };
20
+
///
21
+
/// // But now you can do this, which is equivalent:
0 commit comments