Struct OnceBox

pub(crate) struct OnceBox<T> { pub(in ::sys::sync::once_box) ptr: Atomic<*mut T> }

Fields

ptr: Atomic<*mut T>

Implementations

impl<T> OnceBox<T>

const fn new() -> Self
unsafe fn get_unchecked(&self) -> Pin<&T>

Gets access to the value, assuming it is already initialized and this initialization has been observed by the current thread.

Since all modifications to the pointer have already been observed, the pointer load in this function can be performed with relaxed ordering, potentially allowing the optimizer to turn code like this:

once_box.get_or_init(|| Box::pin(42));
unsafe { once_box.get_unchecked() }

into

once_box.get_or_init(|| Box::pin(42))

Safety

This causes undefined behavior if the assumption above is violated.

fn get_or_init(&self, f: impl FnOnce() -> Pin<Box<T>>) -> Pin<&T>
fn take(&mut self) -> Option<Pin<Box<T>>>
fn initialize(&self, f: impl FnOnce() -> Pin<Box<T>>) -> Pin<&T>

Trait Implementations

impl<T> Drop for OnceBox<T>

fn drop(&mut self)

impl<T: Send + Sync> Sync for OnceBox<T>

impl<T: Send> Send for OnceBox<T>

Auto Trait Implementations

impl<T> !Freeze for OnceBox<T>

impl<T> RefUnwindSafe for OnceBox<T> where Atomic<*mut T>: RefUnwindSafe,

impl<T> Unpin for OnceBox<T> where Atomic<*mut T>: Unpin,

impl<T> UnsafeUnpin for OnceBox<T> where Atomic<*mut T>: UnsafeUnpin,

impl<T> UnwindSafe for OnceBox<T> where Atomic<*mut T>: UnwindSafe,

Blanket Implementations

impl<T> Any for OnceBox<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for OnceBox<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for OnceBox<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for OnceBox<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for OnceBox<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for OnceBox<T>

impl<T, U> Into<U> for OnceBox<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for OnceBox<T> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for OnceBox<T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>