We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6de0005 commit 84b897bCopy full SHA for 84b897b
src/lib.rs
@@ -139,6 +139,13 @@ impl<A: UnsafeAnyExt + ?Sized> TypeMap<A> {
139
})
140
}
141
142
+ /// Find a value in the map and get a reference to it if it exists, or
143
+ /// insert a default value first.
144
+ pub fn get_or_default<K: Key>(&mut self) -> &mut K::Value
145
+ where K::Value: Any + Implements<A> + Default {
146
+ self.entry::<K>().or_insert_with(Default::default)
147
+ }
148
+
149
/// Get the given key's corresponding entry in the map for in-place manipulation.
150
pub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A>
151
where K::Value: Any + Implements<A> {
0 commit comments