Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Mar 1, 2022
1 parent 04a1b9a commit b8e0e39
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/bevy_utils/src/default.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
/// An ergonomic abbreviation for [`Default::default()`] to make initializing structs easier
/// 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 {
/// bar: usize,
/// baz: usize,
/// a: usize,
/// b: usize,
/// c: usize,
/// }
///
/// // Normally you would do this:
/// // 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 {
/// bar: 10,
/// a: 10,
/// ..Default::default()
/// };
///
/// // But now you can do this:
/// // But now you can do this, which is equivalent:
/// let foo = Foo {
/// bar: 10,
/// a: 10,
/// ..default()
/// };
/// ```
#[inline]
pub fn default<T: Default>() -> T {
std::default::Default::default()
}

0 comments on commit b8e0e39

Please sign in to comment.