Struct StreamReader
pub struct StreamReader<S, B> { /* private fields */ }
Convert a Stream of byte chunks into an AsyncRead.
This type performs the inverse operation of ReaderStream.
This type also implements the AsyncBufRead trait, so you can use it
to read a Stream of byte chunks line-by-line. See the examples below.
Example
use Bytes;
use ;
use StreamReader;
#
# async
If the stream produces errors which are not std::io::Error,
the errors can be converted using StreamExt to map each
element.
use Bytes;
use AsyncReadExt;
use StreamReader;
use StreamExt;
#
# async
Using the AsyncBufRead impl, you can read a Stream of byte chunks
line-by-line. Note that you will usually also need to convert the error
type when doing this. See the second example for an explanation of how
to do this.
use ;
use StreamReader;
#
# async
Implementations
impl<S, B> StreamReader<S, B>
fn get_ref(&self) -> &SGets a reference to the underlying stream.
It is inadvisable to directly read from the underlying stream.
fn get_mut(&mut self) -> &mut SGets a mutable reference to the underlying stream.
It is inadvisable to directly read from the underlying stream.
fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut S>Gets a pinned mutable reference to the underlying stream.
It is inadvisable to directly read from the underlying stream.
fn into_inner(self) -> SConsumes this
BufWriter, returning the underlying stream.Note that any leftover data in the internal buffer is lost. If you additionally want access to the internal buffer use
into_inner_with_chunk.
impl<S, B, E> StreamReader<S, B>
where
S: Stream<Item = Result<B, E>>,
B: Buf,
E: Into<Error>,
fn new(stream: S) -> SelfConvert a stream of byte chunks into an
AsyncRead.The item should be a
Resultwith the ok variant being something that implements theBuftrait (e.g.Cursor<Vec<u8>>orBytes). The error should be convertible into an io error.fn into_inner_with_chunk(self) -> (S, Option<B>)Consumes this
StreamReader, returning a Tuple consisting of the underlying stream and an Option of the internal buffer, which is Some in case the buffer contains elements.
Trait Implementations
impl<S, B, E> AsyncBufRead for StreamReader<S, B>
where
S: Stream<Item = Result<B, E>>,
B: Buf,
E: Into<Error>,
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>fn consume(self: Pin<&mut Self>, amt: usize)
impl<S, B, E> AsyncRead for StreamReader<S, B>
where
S: Stream<Item = Result<B, E>>,
B: Buf,
E: Into<Error>,
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>
impl<S: Debug, B: Debug> Debug for StreamReader<S, B>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<S: Sink<T, Error = E>, B, E, T> Sink<T> for StreamReader<S, B>
type Error = E;fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
impl<S: Unpin, B> Unpin for StreamReader<S, B>
Auto Trait Implementations
impl<S, B> Freeze for StreamReader<S, B>
where
S: Freeze,
Option<B>: Freeze,
impl<S, B> RefUnwindSafe for StreamReader<S, B>
where
S: RefUnwindSafe,
Option<B>: RefUnwindSafe,
impl<S, B> Send for StreamReader<S, B>
where
S: Send,
Option<B>: Send,
impl<S, B> Sync for StreamReader<S, B>
where
S: Sync,
Option<B>: Sync,
impl<S, B> UnsafeUnpin for StreamReader<S, B>
where
S: UnsafeUnpin,
Option<B>: UnsafeUnpin,
impl<S, B> UnwindSafe for StreamReader<S, B>
where
S: UnwindSafe,
Option<B>: UnwindSafe,
Blanket Implementations
impl<R> AsyncBufReadExt for StreamReader<S, B>
where
R: AsyncBufRead + ?Sized,
impl<R> AsyncReadExt for StreamReader<S, B>
where
R: AsyncRead + ?Sized,
impl<T> Any for StreamReader<S, B>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for StreamReader<S, B>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for StreamReader<S, B>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for StreamReader<S, B>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for StreamReader<S, B>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for StreamReader<S, B>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for StreamReader<S, B>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>