Skip to content

Commit 5f4cc60

Browse files
authored
Rollup merge of #87685 - notriddle:lazy-from-docs, r=dtolnay
Write docs for SyncOnceCell From and Default impl Part of #51430
2 parents a14b283 + e0172b3 commit 5f4cc60

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

library/std/src/lazy.rs

+30
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ impl<T: UnwindSafe> UnwindSafe for SyncOnceCell<T> {}
8787

8888
#[unstable(feature = "once_cell", issue = "74465")]
8989
impl<T> Default for SyncOnceCell<T> {
90+
/// Creates a new empty cell.
91+
///
92+
/// # Example
93+
///
94+
/// ```
95+
/// #![feature(once_cell)]
96+
///
97+
/// use std::lazy::SyncOnceCell;
98+
///
99+
/// fn main() {
100+
/// assert_eq!(SyncOnceCell::<()>::new(), SyncOnceCell::default());
101+
/// }
102+
/// ```
90103
fn default() -> SyncOnceCell<T> {
91104
SyncOnceCell::new()
92105
}
@@ -118,6 +131,23 @@ impl<T: Clone> Clone for SyncOnceCell<T> {
118131

119132
#[unstable(feature = "once_cell", issue = "74465")]
120133
impl<T> From<T> for SyncOnceCell<T> {
134+
/// Create a new cell with its contents set to `value`.
135+
///
136+
/// # Example
137+
///
138+
/// ```
139+
/// #![feature(once_cell)]
140+
///
141+
/// use std::lazy::SyncOnceCell;
142+
///
143+
/// # fn main() -> Result<(), i32> {
144+
/// let a = SyncOnceCell::from(3);
145+
/// let b = SyncOnceCell::new();
146+
/// b.set(3)?;
147+
/// assert_eq!(a, b);
148+
/// Ok(())
149+
/// # }
150+
/// ```
121151
fn from(value: T) -> Self {
122152
let cell = Self::new();
123153
match cell.set(value) {

0 commit comments

Comments
 (0)