diff --git a/src/sync.rs b/src/sync.rs index 6861033..bd798da 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -922,6 +922,16 @@ where } } +/// A map where values are automatically filled at access. +/// +/// This type can be shared across threads. +/// +/// ``` +/// let map = once_map::LazyMap::new(|x: &i32| x.to_string()); +/// +/// assert_eq!(&map[&3], "3"); +/// assert_eq!(map.get(&-67), "-67"); +/// ``` pub struct LazyMap V> { map: OnceMap, init: F, @@ -941,6 +951,7 @@ impl LazyMap { } } + /// Removes all entries from the map. pub fn clear(&mut self) { self.map.clear(); } diff --git a/src/unsync.rs b/src/unsync.rs index 51f9603..091e125 100644 --- a/src/unsync.rs +++ b/src/unsync.rs @@ -486,6 +486,17 @@ where } } +/// A map where values are automatically filled at access. +/// +/// This type has less overhead than [`crate::sync::LazyMap`] but it cannot be +/// shared across threads. +/// +/// ``` +/// let map = once_map::unsync::LazyMap::new(|x: &i32| x.to_string()); +/// +/// assert_eq!(&map[&3], "3"); +/// assert_eq!(map.get(&-67), "-67"); +/// ``` pub struct LazyMap V> { map: OnceMap, init: F, @@ -505,6 +516,7 @@ impl LazyMap { } } + /// Removes all entries from the map. pub fn clear(&mut self) { self.map.clear(); }