Skip to main content

ResultCell

Struct ResultCell 

Source
pub struct ResultCell<T, W: Waiter, S: StateWord = AtomicU8> { /* private fields */ }
Expand description

Single-producer, single-consumer completion cell for one unit of work.

The state word’s storage is a parameter (StateWord), so each caller keeps the layout it needs; see the layout note.

Implementations§

Source§

impl<T, W: Waiter, S: StateWord> ResultCell<T, W, S>

Source

pub fn new() -> Self

Create an empty cell.

Source

pub fn complete(&self, result: T)

Publish the result, waking the parked waiter if one is registered.

Called exactly once by the producer; a second call is a no-op.

Source

pub fn try_take_ready(&self) -> Option<T>

Take the result if the producer has published it.

Source

pub fn try_take_observed_ready(&self) -> Option<T>

Take the result only if a relaxed load already observed it, for a spin loop that re-checks: the load is the hint, try_take_ready is the decision.

Source

pub fn is_completed(&self) -> bool

Whether the producer has published a result.

Source

pub fn has_registered_waiter(&self) -> bool

Whether a waiter is parked and no result has been published yet.

The complement of is_completed would also answer true before any registration, so this reports the waiting state itself: it is what distinguishes a registration that took effect from one that never ran.

Source

pub unsafe fn register(&self, waiter: &W)

Park a clone of waiter, or replace the parked one when REPLACE_ON_REPEAT is set.

Registration retries until the state is settled, so the waiter is stored from a clone and a failed publish transition costs only that clone. The caller must re-check try_take_ready after this returns: a complete that raced in before the registration does not wake, because it saw no waiter. See the module docs.

§Safety

The waiter cell has one writer at a time, so no other call to register may run on this cell concurrently, and waiter.clone() must not reach back into this cell. The cell has one consumer by construction (a blocking join takes the handle by value; an async poll takes Pin<&mut Self>), and the caller is that consumer.

Trait Implementations§

Source§

impl<T, W: Waiter, S: StateWord> Default for ResultCell<T, W, S>

Source§

fn default() -> Self

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

impl<T, W: Waiter, S: StateWord> Drop for ResultCell<T, W, S>

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, W: Waiter, S: StateWord> Send for ResultCell<T, W, S>

Source§

impl<T: Send, W: Waiter, S: StateWord> Sync for ResultCell<T, W, S>

Auto Trait Implementations§

§

impl<T, W, S = Atomic<u8>> !Freeze for ResultCell<T, W, S>

§

impl<T, W, S = Atomic<u8>> !RefUnwindSafe for ResultCell<T, W, S>

§

impl<T, W, S> Unpin for ResultCell<T, W, S>

§

impl<T, W, S> UnsafeUnpin for ResultCell<T, W, S>

§

impl<T, W, S> UnwindSafe for ResultCell<T, W, S>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.