Write docs for SyncOnceCell From and Default impl
This commit is contained in:
parent
4e21ef2a4e
commit
e0172b380d
1 changed files with 30 additions and 0 deletions
|
@ -87,6 +87,19 @@ impl<T: UnwindSafe> UnwindSafe for SyncOnceCell<T> {}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "once_cell", issue = "74465")]
|
||||||
impl<T> Default for SyncOnceCell<T> {
|
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> {
|
fn default() -> SyncOnceCell<T> {
|
||||||
SyncOnceCell::new()
|
SyncOnceCell::new()
|
||||||
}
|
}
|
||||||
|
@ -118,6 +131,23 @@ impl<T: Clone> Clone for SyncOnceCell<T> {
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "once_cell", issue = "74465")]
|
||||||
impl<T> From<T> for SyncOnceCell<T> {
|
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 {
|
fn from(value: T) -> Self {
|
||||||
let cell = Self::new();
|
let cell = Self::new();
|
||||||
match cell.set(value) {
|
match cell.set(value) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue