Struct wasm_streams::writable::WritableStream
source · [−]pub struct WritableStream { /* private fields */ }
Expand description
WritableStream
s 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
sourceimpl WritableStream
impl WritableStream
sourcepub fn from_raw(raw: WritableStream) -> Self
pub fn from_raw(raw: WritableStream) -> Self
Creates a new WritableStream
from a JavaScript stream.
sourcepub fn from_sink<Si>(sink: Si) -> Selfwhere
Si: Sink<JsValue, Error = JsValue> + 'static,
pub fn from_sink<Si>(sink: Si) -> Selfwhere
Si: Sink<JsValue, Error = JsValue> + 'static,
Creates a new WritableStream
from a Sink
.
Items and errors must be represented as raw JsValue
s.
Use with
and/or sink_map_err
to convert a sink’s items to a JsValue
before passing it to this function.
sourcepub fn as_raw(&self) -> &WritableStream
pub fn as_raw(&self) -> &WritableStream
Acquires a reference to the underlying JavaScript stream.
sourcepub fn into_raw(self) -> WritableStream
pub fn into_raw(self) -> WritableStream
Consumes this WritableStream
, returning the underlying JavaScript stream.
sourcepub fn is_locked(&self) -> bool
pub fn is_locked(&self) -> bool
Returns true
if the stream is locked to a writer.
sourcepub async fn abort(&mut self) -> Result<(), JsValue>
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.
sourcepub async fn abort_with_reason(
&mut self,
reason: &JsValue
) -> Result<(), JsValue>
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.
sourcepub fn get_writer(&mut self) -> WritableStreamDefaultWriter<'_>
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
.
sourcepub fn try_get_writer(
&mut self
) -> Result<WritableStreamDefaultWriter<'_>, Error>
pub fn try_get_writer(
&mut self
) -> Result<WritableStreamDefaultWriter<'_>, Error>
sourcepub fn into_sink(self) -> IntoSink<'static>
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
.
sourcepub fn try_into_sink(self) -> Result<IntoSink<'static>, (Error, Self)>
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
.
sourcepub fn into_async_write(self) -> IntoAsyncWrite<'static>
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
.
sourcepub fn try_into_async_write(
self
) -> Result<IntoAsyncWrite<'static>, (Error, Self)>
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
.