wasm_streams::writable

Struct WritableStream

Source
pub struct WritableStream { /* private fields */ }
Expand description

A WritableStream.

WritableStreams can be created from a raw JavaScript stream with from_raw, or from a Rust Sink with from_sink.

They can be converted into a raw JavaScript stream with into_raw, or into a Rust Sink with into_sink.

Implementations§

Source§

impl WritableStream

Source

pub fn from_raw(raw: WritableStream) -> Self

Creates a new WritableStream from a JavaScript stream.

Source

pub fn from_sink<Si>(sink: Si) -> Self
where Si: Sink<JsValue, Error = JsValue> + 'static,

Creates a new WritableStream from a Sink.

Items and errors must be represented as raw JsValues. Use with and/or sink_map_err to convert a sink’s items to a JsValue before passing it to this function.

Source

pub fn as_raw(&self) -> &WritableStream

Acquires a reference to the underlying JavaScript stream.

Source

pub fn into_raw(self) -> WritableStream

Consumes this WritableStream, returning the underlying JavaScript stream.

Source

pub fn is_locked(&self) -> bool

Returns true if the stream is locked to a writer.

Source

pub async fn abort(&mut self) -> Result<(), JsValue>

Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be immediately moved to an errored state, with any queued-up writes discarded.

If the stream is currently locked to a writer, then this returns an error.

Source

pub async fn abort_with_reason( &mut self, reason: &JsValue, ) -> Result<(), JsValue>

Aborts the stream with the given reason, signaling that the producer can no longer successfully write to the stream and it is to be immediately moved to an errored state, with any queued-up writes discarded.

If the stream is currently locked to a writer, then this returns an error.

Source

pub fn get_writer(&mut self) -> WritableStreamDefaultWriter<'_>

Creates a writer and locks the stream to the new writer.

While the stream is locked, no other writer can be acquired until this one is released.

Panics if the stream is already locked to a writer. For a non-panicking variant, use try_get_writer.

Source

pub fn try_get_writer( &mut self, ) -> Result<WritableStreamDefaultWriter<'_>, Error>

Try to create a writer and lock the stream to the new writer.

While the stream is locked, no other writer can be acquired until this one is released.

If the stream is already locked to a writer, then this returns an error.

Source

pub fn into_sink(self) -> IntoSink<'static>

Converts this WritableStream into a Sink.

Items and errors are represented by their raw JsValue. Use with and/or sink_map_err on the returned stream to convert them to a more appropriate type.

Panics if the stream is already locked to a writer. For a non-panicking variant, use try_into_sink.

Source

pub fn try_into_sink(self) -> Result<IntoSink<'static>, (Error, Self)>

Try to convert this WritableStream into a Sink.

Items and errors are represented by their raw JsValue. Use with and/or sink_map_err on the returned stream to convert them to a more appropriate type.

If the stream is already locked to a writer, then this returns an error along with the original WritableStream.

Source

pub fn into_async_write(self) -> IntoAsyncWrite<'static>

Converts this WritableStream into an AsyncWrite.

The writable stream must accept Uint8Array chunks.

Panics if the stream is already locked to a writer. For a non-panicking variant, use try_into_async_write.

Source

pub fn try_into_async_write( self, ) -> Result<IntoAsyncWrite<'static>, (Error, Self)>

Try to convert this WritableStream into an AsyncWrite.

The writable stream must accept Uint8Array chunks.

If the stream is already locked to a writer, then this returns an error along with the original WritableStream.

Trait Implementations§

Source§

impl Debug for WritableStream

Source§

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

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

impl<Si> From<Si> for WritableStream
where Si: Sink<JsValue, Error = JsValue> + 'static,

Source§

fn from(sink: Si) -> Self

Equivalent to from_sink.

Auto Trait Implementations§

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.