Struct Writer

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

A BufMut adapter which implements io::Write for the inner value.

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

Implementations

impl<B: BufMut> Writer<B>

fn get_ref(&self) -> &B

Gets a reference to the underlying BufMut.

It is inadvisable to directly write to the underlying BufMut.

Examples

use bytes::BufMut;

let buf = Vec::with_capacity(1024).writer();

assert_eq!(1024, buf.get_ref().capacity());
fn get_mut(&mut self) -> &mut B

Gets a mutable reference to the underlying BufMut.

It is inadvisable to directly write to the underlying BufMut.

Examples

use bytes::BufMut;

let mut buf = vec![].writer();

buf.get_mut().reserve(1024);

assert_eq!(1024, buf.get_ref().capacity());
fn into_inner(self) -> B

Consumes this Writer, returning the underlying value.

Examples

use bytes::BufMut;
use std::io;

let mut buf = vec![].writer();
let mut src = &b"hello world"[..];

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

let buf = buf.into_inner();
assert_eq!(*buf, b"hello world"[..]);

Trait Implementations

impl<B: BufMut + Sized> Write for Writer<B>

fn write(&mut self, src: &[u8]) -> Result<usize>
fn flush(&mut self) -> Result<()>

impl<B: Debug> Debug for Writer<B>

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

Auto Trait Implementations

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

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

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

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

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

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

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

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> From<T> for Writer<B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Writer<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 Writer<B> where U: Into<T>,

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

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

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