about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-08-03 19:07:45 +0900
committerGitHub <noreply@github.com>2021-08-03 19:07:45 +0900
commit5f4cc602fd4d7fa773799e24cacfc64159b9c949 (patch)
tree66b2a278a1f58d2bc00b49269bc47d105398c7ee
parenta14b283022af5bdf7507f37e31638fc64ecca298 (diff)
parente0172b380d8260883ddecc060996ea6f5441c54c (diff)
downloadrust-5f4cc602fd4d7fa773799e24cacfc64159b9c949.tar.gz
rust-5f4cc602fd4d7fa773799e24cacfc64159b9c949.zip
Rollup merge of #87685 - notriddle:lazy-from-docs, r=dtolnay
Write docs for SyncOnceCell From and Default impl

Part of #51430
-rw-r--r--library/std/src/lazy.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs
index ca86e569bc1..132733a0525 100644
--- a/library/std/src/lazy.rs
+++ b/library/std/src/lazy.rs
@@ -87,6 +87,19 @@ impl<T: UnwindSafe> UnwindSafe for SyncOnceCell<T> {}
 
 #[unstable(feature = "once_cell", issue = "74465")]
 impl<T> Default for SyncOnceCell<T> {
+    /// Creates a new empty cell.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// #![feature(once_cell)]
+    ///
+    /// use std::lazy::SyncOnceCell;
+    ///
+    /// fn main() {
+    ///     assert_eq!(SyncOnceCell::<()>::new(), SyncOnceCell::default());
+    /// }
+    /// ```
     fn default() -> SyncOnceCell<T> {
         SyncOnceCell::new()
     }
@@ -118,6 +131,23 @@ impl<T: Clone> Clone for SyncOnceCell<T> {
 
 #[unstable(feature = "once_cell", issue = "74465")]
 impl<T> From<T> for SyncOnceCell<T> {
+    /// 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) {