Skip to main content

OnceExt

Trait OnceExt 

Source
pub trait OnceExt {
    type T;

    // Required methods
    fn try_borrow_with<F, E>(&self, f: F) -> Result<&Self::T, E>
       where F: FnOnce() -> Result<Self::T, E>;
    fn try_borrow_mut_with<F, E>(&mut self, f: F) -> Result<&mut Self::T, E>
       where F: FnOnce() -> Result<Self::T, E>;
    fn replace(&mut self, new_value: Self::T) -> Option<Self::T>;
    fn filled(&self) -> bool;
}

Required Associated Types§

Source

type T

Required Methods§

Source

fn try_borrow_with<F, E>(&self, f: F) -> Result<&Self::T, E>
where F: FnOnce() -> Result<Self::T, E>,

This might run f multiple times if different threads start initializing at once.

Source

fn try_borrow_mut_with<F, E>(&mut self, f: F) -> Result<&mut Self::T, E>
where F: FnOnce() -> Result<Self::T, E>,

This might run f multiple times if different threads start initializing at once.

Source

fn replace(&mut self, new_value: Self::T) -> Option<Self::T>

Source

fn filled(&self) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> OnceExt for OnceCell<T>

Source§

type T = T

Source§

fn try_borrow_with<F, E>(&self, f: F) -> Result<&T, E>
where F: FnOnce() -> Result<T, E>,

Source§

fn try_borrow_mut_with<F, E>(&mut self, f: F) -> Result<&mut T, E>
where F: FnOnce() -> Result<T, E>,

Source§

fn replace(&mut self, new_value: T) -> Option<T>

Source§

fn filled(&self) -> bool

Source§

impl<T> OnceExt for OnceLock<T>

Source§

type T = T

Source§

fn try_borrow_with<F, E>(&self, f: F) -> Result<&T, E>
where F: FnOnce() -> Result<T, E>,

Source§

fn try_borrow_mut_with<F, E>(&mut self, f: F) -> Result<&mut T, E>
where F: FnOnce() -> Result<T, E>,

Source§

fn replace(&mut self, new_value: T) -> Option<T>

Source§

fn filled(&self) -> bool

Implementors§