Skip to content

Commit

Permalink
Rollup merge of rust-lang#87685 - notriddle:lazy-from-docs, r=dtolnay
Browse files Browse the repository at this point in the history
Write docs for SyncOnceCell From and Default impl

Part of rust-lang#51430
  • Loading branch information
JohnTitor authored Aug 3, 2021
2 parents 86e6478 + e0172b3 commit 62a9659
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions library/std/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 62a9659

Please sign in to comment.