Skip to main content

OnceSlot

Struct OnceSlot 

Source
pub struct OnceSlot<T> { /* private fields */ }
Expand description

A single-fire, wait-free async result cell.

The generalization of the PENDING-sentinel-AtomicI64 pattern used elsewhere in this crate, for results that aren’t a plain integer. See the module doc above for the exactly-once set contract.

Implementations§

Source§

impl<T> OnceSlot<T>

Source

pub const fn new() -> Self

An empty, not-yet-completed slot.

Source

pub fn set(&self, value: T)

Complete this slot with value, waking whatever’s polling it. Must be called at most once per OnceSlot.

Source

pub fn poll(&self, cx: &Context<'_>) -> Poll<T>

Poll for completion, registering cx’s waker if not yet complete.

Both checks swap the pointer out (not just load) before reconstructing the Box — polling again after an already-observed Ready is not something callers are expected to do (standard Future contract), but doing it anyway must not double-free, and a load-then-Box::from_raw on the fast path would leave a dangling non-null pointer behind for exactly that case.

Trait Implementations§

Source§

impl<T> Default for OnceSlot<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for OnceSlot<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: Send> Send for OnceSlot<T>

Source§

impl<T: Send> Sync for OnceSlot<T>

Auto Trait Implementations§

§

impl<T> !Freeze for OnceSlot<T>

§

impl<T> !RefUnwindSafe for OnceSlot<T>

§

impl<T> Unpin for OnceSlot<T>

§

impl<T> UnsafeUnpin for OnceSlot<T>

§

impl<T> UnwindSafe for OnceSlot<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.