Struct futures_channel::oneshot::Inner

source ·
struct Inner<T> {
    complete: AtomicBool,
    data: Lock<Option<T>>,
    rx_task: Lock<Option<Waker>>,
    tx_task: Lock<Option<Waker>>,
}
Expand description

Internal state of the Receiver/Sender pair above. This is all used as the internal synchronization between the two for send/recv operations.

Fields§

§complete: AtomicBool

Indicates whether this oneshot is complete yet. This is filled in both by Sender::drop and by Receiver::drop, and both sides interpret it appropriately.

For Receiver, if this is true, then it’s guaranteed that data is unlocked and ready to be inspected.

For Sender if this is true then the oneshot has gone away and it can return ready from poll_canceled.

§data: Lock<Option<T>>

The actual data being transferred as part of this Receiver. This is filled in by Sender::complete and read by Receiver::poll.

Note that this is protected by Lock, but it is in theory safe to replace with an UnsafeCell as it’s actually protected by complete above. I wouldn’t recommend doing this, however, unless someone is supremely confident in the various atomic orderings here and there.

§rx_task: Lock<Option<Waker>>

Field to store the task which is blocked in Receiver::poll.

This is filled in when a oneshot is polled but not ready yet. Note that the Lock here, unlike in data above, is important to resolve races. Both the Receiver and the Sender halves understand that if they can’t acquire the lock then some important interference is happening.

§tx_task: Lock<Option<Waker>>

Like rx_task above, except for the task blocked in Sender::poll_canceled. Additionally, Lock cannot be UnsafeCell.

Implementations§

source§

impl<T> Inner<T>

source

fn new() -> Self

source

fn send(&self, t: T) -> Result<(), T>

source

fn poll_canceled(&self, cx: &mut Context<'_>) -> Poll<()>

source

fn is_canceled(&self) -> bool

source

fn drop_tx(&self)

source

fn close_rx(&self)

source

fn try_recv(&self) -> Result<Option<T>, Canceled>

source

fn recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, Canceled>>

source

fn drop_rx(&self)

Auto Trait Implementations§

§

impl<T> !Freeze for Inner<T>

§

impl<T> !RefUnwindSafe for Inner<T>

§

impl<T> Send for Inner<T>
where T: Send,

§

impl<T> Sync for Inner<T>
where T: Send,

§

impl<T> Unpin for Inner<T>
where T: Unpin,

§

impl<T> UnwindSafe for Inner<T>
where T: UnwindSafe,

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.