Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write docs for SyncOnceCell From and Default impl #87685

Merged
merged 1 commit into from Aug 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions library/std/src/lazy.rs
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