From e0172b380d8260883ddecc060996ea6f5441c54c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 1 Aug 2021 14:37:38 -0700 Subject: [PATCH] Write docs for SyncOnceCell From and Default impl --- library/std/src/lazy.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index ca86e569bc127..132733a052510 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -87,6 +87,19 @@ impl UnwindSafe for SyncOnceCell {} #[unstable(feature = "once_cell", issue = "74465")] impl Default for SyncOnceCell { + /// Creates a new empty cell. + /// + /// # Example + /// + /// ``` + /// #![feature(once_cell)] + /// + /// use std::lazy::SyncOnceCell; + /// + /// fn main() { + /// assert_eq!(SyncOnceCell::<()>::new(), SyncOnceCell::default()); + /// } + /// ``` fn default() -> SyncOnceCell { SyncOnceCell::new() } @@ -118,6 +131,23 @@ impl Clone for SyncOnceCell { #[unstable(feature = "once_cell", issue = "74465")] impl From for SyncOnceCell { + /// Create a new cell with its contents set to `value`. + /// + /// # Example + /// + /// ``` + /// #![feature(once_cell)] + /// + /// use std::lazy::SyncOnceCell; + /// + /// # fn main() -> Result<(), i32> { + /// let a = SyncOnceCell::from(3); + /// let b = SyncOnceCell::new(); + /// b.set(3)?; + /// assert_eq!(a, b); + /// Ok(()) + /// # } + /// ``` fn from(value: T) -> Self { let cell = Self::new(); match cell.set(value) {