Skip to main content

ReadStream

Trait ReadStream 

Source
pub trait ReadStream:
    Unpin
    + Send
    + Sync {
    // Required method
    fn read(
        &mut self,
    ) -> impl Future<Output = Result<Buffer, Error>> + MaybeSend;

    // Provided method
    fn read_all(
        &mut self,
    ) -> impl Future<Output = Result<Buffer, Error>> + MaybeSend { ... }
}
Expand description

ReadStream is the internal trait used by OpenDAL to stream data from storage.

Users should not use or import this trait unless they are implementing an Accessor.

§Notes

§Object Safety

ReadStream uses async in trait, making it not object safe, preventing the use of Box<dyn ReadStream>. To address this, we’ve introduced ReadStreamDyn and its compatible type Box<dyn ReadStreamDyn>.

ReadStreamDyn uses Box::pin() to transform the returned future into a BoxedFuture, introducing an additional layer of indirection and an extra allocation. Ideally, ReadStreamDyn should occur only once, at the outermost level of our API.

Required Methods§

Source

fn read(&mut self) -> impl Future<Output = Result<Buffer, Error>> + MaybeSend

Read the next data chunk from the stream.

Provided Methods§

Source

fn read_all( &mut self, ) -> impl Future<Output = Result<Buffer, Error>> + MaybeSend

Read all data from the reader.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ReadStream for ()

Source§

async fn read(&mut self) -> Result<Buffer, Error>

Source§

impl ReadStream for Bytes

Source§

async fn read(&mut self) -> Result<Buffer, Error>

Source§

impl<T> ReadStream for Box<T>
where T: ReadStreamDyn + ?Sized,

§NOTE

Take care about the deref_mut() here. This makes sure that we are calling functions upon &mut T instead of &mut Box<T>. The later could result in infinite recursion.

Source§

async fn read(&mut self) -> Result<Buffer, Error>

Source§

async fn read_all(&mut self) -> Result<Buffer, Error>

Implementors§

Source§

impl ReadStream for Buffer

Source§

impl ReadStream for HttpBody

Source§

impl<ONE, TWO> ReadStream for TwoWays<ONE, TWO>
where ONE: ReadStream, TWO: ReadStream,

Source§

impl<ONE, TWO, THREE> ReadStream for ThreeWays<ONE, TWO, THREE>
where ONE: ReadStream, TWO: ReadStream, THREE: ReadStream,

Source§

impl<ONE, TWO, THREE, FOUR> ReadStream for FourWays<ONE, TWO, THREE, FOUR>
where ONE: ReadStream, TWO: ReadStream, THREE: ReadStream, FOUR: ReadStream,