[][src]Struct wasm_streams::readable::ReadableStream

pub struct ReadableStream { /* fields omitted */ }

A ReadableStream.

ReadableStreams can be created from a raw JavaScript stream with from_raw, or from a Rust Stream with from_stream.

They can be converted into a raw JavaScript stream with into_raw, or into a Rust Stream with into_stream.

Implementations

impl ReadableStream[src]

pub fn from_raw(raw: ReadableStream) -> Self[src]

Creates a new ReadableStream from a JavaScript stream.

pub fn from_stream<St>(stream: St) -> Self where
    St: Stream<Item = Result<JsValue, JsValue>> + 'static, 
[src]

Creates a new ReadableStream from a Stream.

Items and errors must be represented as raw JsValues. Use map, map_ok and/or map_err to convert a stream's items to a JsValue before passing it to this function.

pub fn as_raw(&self) -> &ReadableStream[src]

Acquires a reference to the underlying JavaScript stream.

pub fn into_raw(self) -> ReadableStream[src]

Consumes this ReadableStream, returning the underlying JavaScript stream.

pub fn is_locked(&self) -> bool[src]

Returns true if the stream is locked to a reader.

pub async fn cancel<'_>(&'_ mut self) -> Result<(), JsValue>[src]

Cancels the stream, signaling a loss of interest in the stream by a consumer.

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

pub async fn cancel_with_reason<'_, '_>(
    &'_ mut self,
    reason: &'_ JsValue
) -> Result<(), JsValue>
[src]

Cancels the stream, signaling a loss of interest in the stream by a consumer.

The supplied reason will be given to the underlying source, which may or may not use it.

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

pub fn get_reader(&mut self) -> ReadableStreamDefaultReader[src]

Creates a default reader and locks the stream to the new reader.

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

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

pub fn try_get_reader(&mut self) -> Result<ReadableStreamDefaultReader, Error>[src]

Try to create a default reader and lock the stream to the new reader.

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

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

pub async fn pipe_to<'a>(
    &'a mut self,
    dest: &'a mut WritableStream
) -> Result<(), JsValue>
[src]

Pipes this readable stream to a given writable stream.

Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.

This returns () if the pipe completes successfully, or Err(error) if any error was encountered during the process.

pub async fn pipe_to_with_options<'a, '_>(
    &'a mut self,
    dest: &'a mut WritableStream,
    options: &'_ PipeOptions
) -> Result<(), JsValue>
[src]

Pipes this readable stream to a given writable stream.

Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.

Errors and closures of the source and destination streams propagate as follows:

  • An error in the source readable stream will abort the destination writable stream, unless options.prevent_abort is true.
  • An error in the destination writable stream will cancel the source readable stream, unless options.prevent_cancel is true.
  • When the source readable stream closes, the destination writable stream will be closed, unless options.prevent_close is true.
  • If the destination writable stream starts out closed or closing, the source readable stream will be canceled, unless unless options.prevent_cancel is true.

This returns () if the pipe completes successfully, or Err(error) if any error was encountered during the process.

pub fn tee(self) -> (ReadableStream, ReadableStream)[src]

Tees this readable stream, returning the two resulting branches as new ReadableStream instances.

Teeing a stream will lock it, preventing any other consumer from acquiring a reader. To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be propagated to the stream's underlying source.

Note that the chunks seen in each branch will be the same object. If the chunks are not immutable, this could allow interference between the two branches.

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

pub fn try_tee(self) -> Result<(ReadableStream, ReadableStream), (Error, Self)>[src]

Tries to tee this readable stream, returning the two resulting branches as new ReadableStream instances.

Teeing a stream will lock it, preventing any other consumer from acquiring a reader. To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be propagated to the stream's underlying source.

Note that the chunks seen in each branch will be the same object. If the chunks are not immutable, this could allow interference between the two branches.

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

pub fn into_stream(self) -> IntoStream<'static>[src]

Converts this ReadableStream into a Stream.

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

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

pub fn try_into_stream(self) -> Result<IntoStream<'static>, (Error, Self)>[src]

Try to convert this ReadableStream into a Stream.

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

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

Trait Implementations

impl Debug for ReadableStream[src]

impl<St> From<St> for ReadableStream where
    St: Stream<Item = Result<JsValue, JsValue>> + 'static, 
[src]

fn from(stream: St) -> Self[src]

Equivalent to from_stream.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.