Skip to content

Commit

Permalink
Updated FromWorld Documentation to mention Default (bevyengine#14954
Browse files Browse the repository at this point in the history
)

# Objective

- Fixes bevyengine#14860

## Solution

- Added a line of documentation to `FromWorld`'s trait definition
mention the `Default` blanket implementation.
- Added custom documentation to the `from_world` method for the
`Default` blanket implementation. This ensures when inspecting the
`from_world` function within an IDE, the tooltip will explicitly state
the `default()` method will be used for any `Default` types.

## Testing

- CI passes.
  • Loading branch information
bushrat011899 authored Aug 28, 2024
1 parent 210c79c commit 371e07e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2949,12 +2949,15 @@ unsafe impl Sync for World {}
/// using data from the supplied [`World`].
///
/// This can be helpful for complex initialization or context-aware defaults.
///
/// [`FromWorld`] is automatically implemented for any type implementing [`Default`].
pub trait FromWorld {
/// Creates `Self` using data from the given [`World`].
fn from_world(world: &mut World) -> Self;
}

impl<T: Default> FromWorld for T {
/// Creates `Self` using [`default()`](`Default::default`).
fn from_world(_world: &mut World) -> Self {
T::default()
}
Expand Down

0 comments on commit 371e07e

Please sign in to comment.