Trait bytes::BufMut
[−]
[src]
pub trait BufMut { fn remaining_mut(&self) -> usize; unsafe fn advance_mut(&mut self, cnt: usize); unsafe fn bytes_mut(&mut self) -> &mut [u8]; fn has_remaining_mut(&self) -> bool { ... } fn copy_from<S: Source>(&mut self, src: S) where Self: Sized { ... } fn copy_from_slice(&mut self, src: &[u8]) { ... } fn put_str(&mut self, src: &str) { ... } fn put_u8(&mut self, n: u8) { ... } fn put_i8(&mut self, n: i8) { ... } fn put_u16<T: ByteOrder>(&mut self, n: u16) { ... } fn put_i16<T: ByteOrder>(&mut self, n: i16) { ... } fn put_u32<T: ByteOrder>(&mut self, n: u32) { ... } fn put_i32<T: ByteOrder>(&mut self, n: i32) { ... } fn put_u64<T: ByteOrder>(&mut self, n: u64) { ... } fn put_i64<T: ByteOrder>(&mut self, n: i64) { ... } fn put_uint<T: ByteOrder>(&mut self, n: u64, nbytes: usize) { ... } fn put_int<T: ByteOrder>(&mut self, n: i64, nbytes: usize) { ... } fn put_f32<T: ByteOrder>(&mut self, n: f32) { ... } fn put_f64<T: ByteOrder>(&mut self, n: f64) { ... } fn by_ref(&mut self) -> &mut Self where Self: Sized { ... } fn take_mut(self, limit: usize) -> TakeMut<Self> where Self: Sized { ... } fn writer(self) -> Writer<Self> where Self: Sized { ... } }
A trait for values that provide sequential write access to bytes.
Required Methods
fn remaining_mut(&self) -> usize
Returns the number of bytes that can be written to the BufMut
unsafe fn advance_mut(&mut self, cnt: usize)
Advance the internal cursor of the BufMut
unsafe fn bytes_mut(&mut self) -> &mut [u8]
Returns a mutable slice starting at the current BufMut position and of
length between 0 and BufMut::remaining()
.
The returned byte slice may represent uninitialized memory.
Provided Methods
fn has_remaining_mut(&self) -> bool
Returns true iff there is any more space for bytes to be written
fn copy_from<S: Source>(&mut self, src: S) where Self: Sized
Copies bytes from src
into self
Panics
Panics if self
does not have enough capacity to copy all the data
from src
fn copy_from_slice(&mut self, src: &[u8])
Copies bytes from the given slice into the BufMut
and advance the
cursor by the number of bytes written.
Returns the number of bytes written.
use bytes::BufMut; use std::io::Cursor; let mut dst = [0; 6]; { let mut buf = Cursor::new(&mut dst); buf.copy_from_slice(b"hello"); assert_eq!(1, buf.remaining_mut()); } assert_eq!(b"hello\0", &dst);
fn put_str(&mut self, src: &str)
Writes the given string into self.
Panics
The function panics if self
does not have enough remaining capacity
to write the full string.
fn put_u8(&mut self, n: u8)
Writes an unsigned 8 bit integer to the BufMut.
fn put_i8(&mut self, n: i8)
Writes a signed 8 bit integer to the BufMut.
fn put_u16<T: ByteOrder>(&mut self, n: u16)
Writes an unsigned 16 bit integer to the BufMut.
fn put_i16<T: ByteOrder>(&mut self, n: i16)
Writes a signed 16 bit integer to the BufMut.
fn put_u32<T: ByteOrder>(&mut self, n: u32)
Writes an unsigned 32 bit integer to the BufMut.
fn put_i32<T: ByteOrder>(&mut self, n: i32)
Writes a signed 32 bit integer to the BufMut.
fn put_u64<T: ByteOrder>(&mut self, n: u64)
Writes an unsigned 64 bit integer to the BufMut.
fn put_i64<T: ByteOrder>(&mut self, n: i64)
Writes a signed 64 bit integer to the BufMut.
fn put_uint<T: ByteOrder>(&mut self, n: u64, nbytes: usize)
Writes an unsigned n-bytes integer to the BufMut.
If the given integer is not representable in the given number of bytes,
this method panics. If nbytes > 8
, this method panics.
fn put_int<T: ByteOrder>(&mut self, n: i64, nbytes: usize)
Writes a signed n-bytes integer to the BufMut.
If the given integer is not representable in the given number of bytes,
this method panics. If nbytes > 8
, this method panics.
fn put_f32<T: ByteOrder>(&mut self, n: f32)
Writes a IEEE754 single-precision (4 bytes) floating point number to the BufMut.
fn put_f64<T: ByteOrder>(&mut self, n: f64)
Writes a IEEE754 double-precision (8 bytes) floating point number to the BufMut.
fn by_ref(&mut self) -> &mut Self where Self: Sized
Creates a "by reference" adaptor for this instance of BufMut
fn take_mut(self, limit: usize) -> TakeMut<Self> where Self: Sized
Create an adapter which will limit at most limit
bytes from it.
fn writer(self) -> Writer<Self> where Self: Sized
Return a Write
for the value. Allows using a BufMut
as an
io::Write