whatwg_streams 0.1.0-alpha.11

whatwg_streams for rust
Documentation
use super::{readable::ReadableByteStreamController, shared::StreamResult};
use crate::platform::MaybeSend;

pub trait ReadableByteSource: MaybeSend + 'static {
    fn start(
        &mut self,
        #[allow(unused)] controller: &mut ReadableByteStreamController,
    ) -> impl Future<Output = StreamResult<()>> + MaybeSend {
        async { Ok(()) }
    }

    /// Produce bytes into the stream.
    ///
    /// Optional (spec: a source with no `pull` gets a no-op pull algorithm) — implement it for the
    /// usual pull-driven source; omit it for one that enqueues everything in `start()` or pushes
    /// via a captured controller.
    ///
    /// Hand chunks to the controller with `controller.enqueue(impl Into<Bytes>)`:
    /// a chunk already held as `Bytes` transfers in without a copy. A source
    /// reading from elsewhere owns its read buffer (e.g. fill a `BytesMut`, then
    /// `enqueue(buf.freeze())`) so the bytes reach the queue without being copied
    /// through the controller. Signal end-of-stream with `controller.close()`.
    fn pull(
        &mut self,
        #[allow(unused)] controller: &mut ReadableByteStreamController,
    ) -> impl Future<Output = StreamResult<()>> + MaybeSend {
        async { Ok(()) }
    }

    fn cancel(
        &mut self,
        #[allow(unused)] reason: Option<String>,
    ) -> impl Future<Output = StreamResult<()>> + MaybeSend {
        async { Ok(()) }
    }
}