Sender

Struct Sender 

Source
pub struct Sender<T: State = TaskCompletion> { /* private fields */ }
Expand description

Completion notifier for one-shot tasks

Optimized implementation using direct RawWaker storage + AtomicU8:

  • Zero Box allocation: stores waker components directly in atomic fields
  • Faster creation than Notify (no waitlist) or AtomicWaker (no state machine)
  • Lower memory footprint (three atomic fields: data ptr, vtable ptr, state)
  • Direct waker management without intermediate futures or heap allocation
  • Single Arc allocation for both sender and receiver

一次性任务完成通知器

使用直接 RawWaker 存储 + AtomicU8 的优化实现:

  • 零 Box 分配:直接在原子字段中存储 waker 组件
  • 比 Notify(无等待列表)或 AtomicWaker(无状态机)创建更快
  • 更小的内存占用(三个原子字段:data 指针、vtable 指针、状态)
  • 直接管理 waker,无中间 future 或堆分配
  • 发送器和接收器共享单个 Arc 分配

Implementations§

Source§

impl<T: State> Sender<T>

Source

pub fn new() -> (Self, Receiver<T>)

Create a new oneshot completion notifier with receiver

创建一个新的 oneshot 完成通知器和接收器

§Returns

Returns a tuple of (notifier, receiver)

返回 (通知器, 接收器) 元组

Source

pub fn notify(&self, state: T)

Notify completion with the given state

使用给定状态通知完成

Auto Trait Implementations§

§

impl<T> Freeze for Sender<T>

§

impl<T = TaskCompletion> !RefUnwindSafe for Sender<T>

§

impl<T> Send for Sender<T>

§

impl<T> Sync for Sender<T>

§

impl<T> Unpin for Sender<T>

§

impl<T = TaskCompletion> !UnwindSafe for Sender<T>

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.