Skip to content

Commit

Permalink
Docs clarity for init_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Nov 22, 2021
1 parent afcdf07 commit 0365476
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,13 @@ impl App {
self
}

/// Initialize a resource with default values by adding it to the [`World`]
/// Initialize a resource with standard starting values by adding it to the [`World`]
///
/// If the resource already exists, nothing happens.
///
/// The resource must implement either the `Default` or [`FromWorld`] trait.
/// The resource must implement the [`FromWorld`] trait.
/// If the `Default` trait is implemented, the `FromWorld` trait will use
/// the `Default::default` method to initialize the resource.
///
/// ## Example
/// ```
Expand All @@ -663,11 +665,11 @@ impl App {
self
}

/// Initialize a non-send resource with default values by adding it to the [`World`]
/// Initialize a non-send resource with standard starting values by adding it to the [`World`]
///
/// If the resource already exists, nothing happens.
///
/// The resource must implement either the `Default` or [`FromWorld`] trait.
/// The resource must implement the [`FromWorld`] trait.
/// If the `Default` trait is implemented, the `FromWorld` trait will use
/// the `Default::default` method to initialize the resource.
pub fn init_non_send_resource<R: 'static + FromWorld>(&mut self) -> &mut Self {
self.world.init_non_send_resource::<R>();
self
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<'w, 's> Commands<'w, 's> {
self.queue.push(InsertOrSpawnBatch { bundles_iter });
}

/// Inserts a resource with default values to the [`World`].
/// Inserts a resource with standard starting values to the [`World`].
///
/// If the resource already exists, nothing happens.
///
Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,13 @@ impl World {
}
}

/// Inserts a new resource with default values.
/// Inserts a new resource with standard starting values.
///
/// If the resource already exists, nothing happens.
///
/// Uses the [`FromWorld`] trait to determine values,
/// which has a blanket impl for all `R: Default`.
/// The value given by the [`FromWorld::from_world`] method will be used.
/// Note that any resource with the `Default` trait automatically implements `FromWorld`,
/// and those default values will be here instead.
#[inline]
pub fn init_resource<R: Resource + FromWorld>(&mut self) {
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
Expand All @@ -620,12 +621,13 @@ impl World {
unsafe { self.insert_resource_with_id(component_id, value) };
}

/// Inserts a new non-send resource with default values.
/// Inserts a new non-send resource with standard starting values.
///
/// If the resource already exists, nothing happens.
///
/// Uses the [`FromWorld`] trait to determine values,
/// which has a blanket impl for all `R: Default`.
/// The value given by the [`FromWorld::from_world`] method will be used.
/// Note that any resource with the `Default` trait automatically implements `FromWorld`,
/// and those default values will be here instead.
#[inline]
pub fn init_non_send_resource<R: 'static + FromWorld>(&mut self) {
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
Expand Down

0 comments on commit 0365476

Please sign in to comment.