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

Returns the number of bytes that can be written to the MutBuf

Advance the internal cursor of the MutBuf

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

Returns true iff there is any more space for bytes to be written

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);

Write a single byte to the MuBuf

Implementors