You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement GenericWriteStorage::get_mut_or_default, which either fetches an existing component, or calls Default::default on the component type, inserts the newly created struct in to the storage, and returns a mutable reference to it.
This can never fail.
Motivation
I found myself writing a lot of code along the lines of
563: Optionized get_mut_or_default r=torkleyy a=JaniM
Fixes#561
Alternative to #562 . Implements an Option API instead of panicking if the entity is dead
I have no idea how I managed to mess up the branch name.
Co-authored-by: Jani Mustonen <[email protected]>
Description
Implement
GenericWriteStorage::get_mut_or_default
, which either fetches an existing component, or callsDefault::default
on the component type, inserts the newly created struct in to the storage, and returns a mutable reference to it.This can never fail.
Motivation
I found myself writing a lot of code along the lines of
Verbose, and extremely repetitive. The new function offers a shorthand:
Drawbacks
An extra function to maintain. However, it builds on the existing methods of
GenericWriteStorage
, so the maintenance impact should be near zero.`Unresolved questions
Opened a PR for this.
The text was updated successfully, but these errors were encountered: