Skip to main content

OneSender

Struct OneSender 

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

唯一交值句柄(sender handle)。

不可克隆(Clone);Self::send 消耗自身,表达本份只能交值一次。 不交值而直接释放,会使等待端取得 WaitError::SenderDropped。 在满足 T: Send 时可转交其它线程,不要求 T: Sync。

Implementations§

Source§

impl<T> OneSender<T>

Source

pub fn send(self, value: T) -> Result<(), SendError<T>>

同步交出原值,消耗本句柄(handle)。

成功表示值已被接受,不承诺等待端已观察到值。 接收已关闭则返回 SendError,可拆出同一个原值及 crate::SendErrorKind::ReceiverClosed;不复制或隐式丢弃原值。

不等待接收方、调度或锁;条件原子更新(CAS)可因实际并发修改重试。 原值正常交接不新增分配。通知及原值清理可执行用户代码,其恐慌(panic)会传播; 已成立的接受事实不会因此回退。回调本身的耗时不属于非阻塞保证。

Examples found in repository?
examples/api_bounds.rs (line 24)
22fn borrowed_wait<R: Runtime>(runtime: &R, value: &str) {
23    let (_wait, sender) = runtime.wait_one_timeout::<&str>(Duration::from_millis(2));
24    let _sent = sender.send(value);
25    let (_wait, sender) = runtime.wait_any_timeout::<Cell<u32>>(Duration::from_millis(3));
26    let _sent = sender.send(Cell::new(1));
27}

Trait Implementations§

Source§

impl<T> Drop for OneSender<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

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for OneSender<T>

§

impl<T> !UnwindSafe for OneSender<T>

§

impl<T> Forget for OneSender<T>

§

impl<T> Freeze for OneSender<T>
where Option<Arc<OneShared<T>>>: Freeze,

§

impl<T> Move for OneSender<T>

§

impl<T> Send for OneSender<T>
where Option<Arc<OneShared<T>>>: Send,

§

impl<T> Sync for OneSender<T>
where Option<Arc<OneShared<T>>>: Sync,

§

impl<T> Unpin for OneSender<T>
where Option<Arc<OneShared<T>>>: Unpin,

§

impl<T> UnsafeUnpin for OneSender<T>
where Option<Arc<OneShared<T>>>: UnsafeUnpin,

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> OpaqueAttachment for T
where T: Send + Sync + 'static,

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.