Updated FromWorld Documentation to mention Default (#14954)

# Objective

- Fixes #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.
This commit is contained in:
Zachary Harrold 2024-08-28 21:37:31 +10:00 committed by GitHub
parent 210c79c9f9
commit 371e07e77d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()
}