From 9110a39302ad0fb7c824fb78e4b48ee17e788f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Wed, 28 Aug 2024 15:58:30 +0200 Subject: [PATCH] Add a few comments --- src/sync.rs | 11 +++++++++++ src/unsync.rs | 12 ++++++++++++ 2 files changed, 23 insertions(+) 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(); }