[−][src]Trait kf_protocol::bytes::BufMutExt
Extra methods for implementations of BufMut.
Provided methods
fn limit(self, limit: usize) -> Limit<Self>
Creates an adaptor which can write at most limit bytes to self.
Examples
use bytes::{BufMut, buf::BufMutExt}; let arr = &mut [0u8; 128][..]; assert_eq!(arr.remaining_mut(), 128); let dst = arr.limit(10); assert_eq!(dst.remaining_mut(), 10);
fn writer(self) -> Writer<Self>
Creates an adaptor which implements the Write trait for self.
This function returns a new value which implements Write by adapting
the Write trait functions to the BufMut trait functions. Given that
BufMut operations are infallible, none of the Write functions will
return with Err.
Examples
use bytes::{BufMut, buf::BufMutExt}; use std::io::Write; let mut buf = vec![].writer(); let num = buf.write(&b"hello world"[..]).unwrap(); assert_eq!(11, num); let buf = buf.into_inner(); assert_eq!(*buf, b"hello world"[..]);
fn chain_mut<U>(self, next: U) -> Chain<Self, U> where
U: BufMut,
U: BufMut,
Creates an adapter which will chain this buffer with another.
The returned BufMut instance will first write to all bytes from
self. Afterwards, it will write to next.
Examples
use bytes::{BufMut, buf::BufMutExt}; let mut a = [0u8; 5]; let mut b = [0u8; 6]; let mut chain = (&mut a[..]).chain_mut(&mut b[..]); chain.put_slice(b"hello world"); assert_eq!(&a[..], b"hello"); assert_eq!(&b[..], b" world");