FutureWriter

Struct FutureWriter 

Source
pub struct FutureWriter<T: 'static> { /* private fields */ }
Expand description

Represents the writable end of a Component Model future.

A FutureWriter can be used to send a single value of T to the other end of a future. In a sense this is similar to a oneshot channel in Rust.

Implementations§

Source§

impl<T> FutureWriter<T>

Source

pub fn write(self, value: T) -> FutureWrite<T>

Write the specified value to this future.

This method is equivalent to an async fn which sends the value into this future. The asynchronous operation acts as a rendezvous where the operation does not complete until the other side has successfully received the value.

§Return Value

The returned FutureWrite is a future that can be .await’d. The return value of this future is:

  • Ok(()) - the value was sent and received. The self value was consumed along the way and will no longer be accessible.
  • Err(FutureWriteError { value }) - an attempt was made to send value but the other half of this FutureWriter was dropped before the value was received. This consumes self because the channel is now dropped, but value is returned in case the caller wants to reuse it.
§Cancellation

The returned future can be cancelled normally via drop which means that the value provided here, along with this FutureWriter itself, will be lost. There is also FutureWrite::cancel which can be used to possibly re-acquire value and self if the operation was cancelled. In such a situation the operation can be retried at a future date.

Trait Implementations§

Source§

impl<T> Debug for FutureWriter<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for FutureWriter<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FutureWriter<T>

§

impl<T> RefUnwindSafe for FutureWriter<T>

§

impl<T> Send for FutureWriter<T>

§

impl<T> Sync for FutureWriter<T>

§

impl<T> Unpin for FutureWriter<T>

§

impl<T> UnwindSafe for FutureWriter<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.