mirror of
https://github.com/bevyengine/bevy
synced 2024-12-30 06:53:13 +00:00
b4071ca370
# Objective If a `Resource` implements `FromWorld` or `Default`, it's nicer to be able to write: ```rust let foo = world.get_resource_or_init::<Foo>(); ``` Rather than: ```rust let foo = world.get_resource_or_insert_with(Foo::default); ``` The latter is also not possible if a type implements `FromWorld` only, and not `Default`. ## Solution Added: ```rust impl World { pub fn get_resource_or_init<R: Resource + FromWorld>(&mut self) -> Mut<'_, R>; } ``` Turns out all current in-engine uses of `get_resource_or_insert_with` are exactly the above, so they've also been replaced. ## Testing - Added a doc-test. - Also added a doc-test for `World::get_resource_or_insert_with`. |
||
---|---|---|
.. | ||
base.rs | ||
collections.rs | ||
event_cursor.rs | ||
iterators.rs | ||
mod.rs | ||
mut_iterators.rs | ||
mutator.rs | ||
reader.rs | ||
registry.rs | ||
send_event.rs | ||
update.rs | ||
writer.rs |