StreamWriter

Struct StreamWriter 

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

Represents the writable end of a Component Model stream.

Implementations§

Source§

impl<T> StreamWriter<T>

Source

pub fn write(&mut self, values: Vec<T>) -> StreamWrite<'_, T>

Initiate a write of the values provided into this stream.

This method is akin to an async fn except that the returned StreamWrite future can also be cancelled via StreamWrite::cancel to re-acquire undelivered values.

This method will perform at most a single write of the values provided. The returned future will resolve once the write has completed.

§Return Values

The returned StreamWrite future returns a tuple of (result, buf). The result can be StreamResult::Complete(n) meaning that n values were sent from values into this writer. A result of StreamResult::Dropped means that no values were sent and the other side has hung-up and sending values will no longer be possible.

The buf returned is an AbiBuffer<T> which retains ownership of the original values provided here. That can be used to re-acquire values through the AbiBuffer::into_vec method. The buf maintains an internal cursor of how many values have been written and if the write should be resumed to write the entire buffer then the StreamWriter::write_buf method can be used to resume writing at the next value in the buffer.

§Cancellation

The returned StreamWrite future can be cancelled like any other Rust future via drop, but this means that values will be lost within the future. The StreamWrite::cancel method can be used to re-acquire the in-progress write that is being done with values. This is effectively a way of forcing the future to immediately resolve.

Note that if this future is cancelled via drop it does not mean that no values were sent. It may be possible that values were still sent despite being cancelled. Cancelling a write and determining what happened must be done with StreamWrite::cancel.

Source

pub fn write_buf(&mut self, values: AbiBuffer<T>) -> StreamWrite<'_, T>

Same as StreamWriter::write, except this takes AbiBuffer<T> instead of Vec<T>.

Source

pub async fn write_all(&mut self, values: Vec<T>) -> Vec<T>

Writes all of the values provided into this stream.

This is a higher-level method than StreamWriter::write and does not expose cancellation for example. This will successively attempt to write all of values provided into this stream. Upon completion the same vector will be returned and any remaining elements in the vector were not sent because the stream was dropped.

Source

pub async fn write_one(&mut self, value: T) -> Option<T>

Writes the singular value provided

This is a higher-level method than StreamWriter::write and does not expose cancellation for example. This will attempt to send value on this stream.

If the other end hangs up then the value is returned back as Some(value), otherwise None is returned indicating the value was sent.

Trait Implementations§

Source§

impl<T> Debug for StreamWriter<T>

Source§

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

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

impl<T> Drop for StreamWriter<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for StreamWriter<T>

§

impl<T> RefUnwindSafe for StreamWriter<T>

§

impl<T> Send for StreamWriter<T>

§

impl<T> Sync for StreamWriter<T>

§

impl<T> Unpin for StreamWriter<T>

§

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