Trait bytes::buf::MutBuf
[−]
[src]
pub trait MutBuf: Sized { fn remaining(&self) -> usize; unsafe fn advance(&mut self, cnt: usize); unsafe fn mut_bytes<'a>(&'a mut self) -> &'a mut [u8]; fn has_remaining(&self) -> bool { ... } fn write_slice(&mut self, src: &[u8]) -> usize { ... } fn write_byte(&mut self, byte: u8) -> bool { ... } }
A trait for values that provide sequential write access to bytes.
Required Methods
fn remaining(&self) -> usize
Returns the number of bytes that can be written to the MutBuf
unsafe fn advance(&mut self, cnt: usize)
Advance the internal cursor of the MutBuf
unsafe fn mut_bytes<'a>(&'a mut self) -> &'a mut [u8]
Returns a mutable slice starting at the current MutBuf position and of
length between 0 and MutBuf::remaining()
.
The returned byte slice may represent uninitialized memory.
Provided Methods
fn has_remaining(&self) -> bool
Returns true iff there is any more space for bytes to be written
fn write_slice(&mut self, src: &[u8]) -> usize
Write bytes from the given slice into the MutBuf
and advance the
cursor by the number of bytes written.
Returns the number of bytes written.
use bytes::{MutSliceBuf, Buf, MutBuf}; let mut dst = [0; 6]; { let mut buf = MutSliceBuf::wrap(&mut dst); buf.write_slice(b"hello"); assert_eq!(1, buf.remaining()); } assert_eq!(b"hello\0", &dst);
fn write_byte(&mut self, byte: u8) -> bool
Write a single byte to the MuBuf
Implementors
impl MutBuf for MutByteBuf
impl MutBuf for RingBuf
impl<'a> MutBuf for MutSliceBuf<'a>
impl<T: MutBuf> MutBuf for Take<T>
impl MutBuf for Vec<u8>