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
But the analogue of Entry's or_default is missing from Option: Option should have a method get_or_default, that does conceptually the same as or_default by doing self.get_or_insert_with(|| Default::default()) (returns &mut T).
(This use case occurs often in some projects of mine..)
There is some symmetry between the methods of
HashMap'sEntryandOption, e.g.https://doc.rust-lang.org/nightly/std/collections/hash_map/enum.Entry.html#method.or_insert
https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.get_or_insert
https://doc.rust-lang.org/nightly/std/collections/hash_map/enum.Entry.html#method.or_insert_with
https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.get_or_insert_with
But the analogue of
Entry'sor_defaultis missing fromOption:Optionshould have a methodget_or_default, that does conceptually the same asor_defaultby doingself.get_or_insert_with(|| Default::default())(returns&mut T).(This use case occurs often in some projects of mine..)