Struct Reader

pub struct Reader<B> { /* private fields */ }

A Buf adapter which implements io::Read for the inner value.

This struct is generally created by calling reader() on Buf. See documentation of reader() for more details.

Implementations

impl<B: Buf> Reader<B>

fn get_ref(&self) -> &B

Gets a reference to the underlying Buf.

It is inadvisable to directly read from the underlying Buf.

Examples

use bytes::Buf;

let buf = b"hello world".reader();

assert_eq!(b"hello world", buf.get_ref());
fn get_mut(&mut self) -> &mut B

Gets a mutable reference to the underlying Buf.

It is inadvisable to directly read from the underlying Buf.

fn into_inner(self) -> B

Consumes this Reader, returning the underlying value.

Examples

use bytes::Buf;
use std::io;

let mut buf = b"hello world".reader();
let mut dst = vec![];

io::copy(&mut buf, &mut dst).unwrap();

let buf = buf.into_inner();
assert_eq!(0, buf.remaining());

Trait Implementations

impl<B: Buf + Sized> BufRead for Reader<B>

fn fill_buf(&mut self) -> Result<&[u8]>
fn consume(&mut self, amt: usize)

impl<B: Buf + Sized> Read for Reader<B>

fn read(&mut self, dst: &mut [u8]) -> Result<usize>

impl<B: Debug> Debug for Reader<B>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<B> Freeze for Reader<B> where B: Freeze,

impl<B> RefUnwindSafe for Reader<B> where B: RefUnwindSafe,

impl<B> Send for Reader<B> where B: Send,

impl<B> Sync for Reader<B> where B: Sync,

impl<B> Unpin for Reader<B> where B: Unpin,

impl<B> UnsafeUnpin for Reader<B> where B: UnsafeUnpin,

impl<B> UnwindSafe for Reader<B> where B: UnwindSafe,

Blanket Implementations

impl<T> Any for Reader<B> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Reader<B> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Reader<B> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Reader<B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Reader<B> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Reader<B> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Reader<B> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>