Struct bytes::ByteBuf
[−]
[src]
pub struct ByteBuf { /* fields omitted */ }
A buffer backed by BytesMut
Methods
impl ByteBuf
[src]
fn new() -> ByteBuf
Create a new ByteBuf
with 8kb capacity
fn with_capacity(cap: usize) -> ByteBuf
Create a new ByteBuf
with cap
capacity
fn from_bytes(bytes: BytesMut) -> ByteBuf
Create a new ByteBuf
backed by bytes
fn from_slice<T: AsRef<[u8]>>(bytes: T) -> ByteBuf
Create a new ByteBuf
containing the given slice
fn capacity(&self) -> usize
Return the number of bytes the buffer can contain
fn position(&self) -> usize
Return the read cursor position
fn set_position(&mut self, position: usize)
Set the read cursor position
fn len(&self) -> usize
Return the number of buffered bytes
fn is_empty(&self) -> bool
Returns true
if the buffer contains no unread bytes
fn clear(&mut self)
Clears the buffer, removing any written data
fn drain_read(&mut self) -> BytesMut
Splits the buffer into two at the current read index.
fn drain_to(&mut self, at: usize) -> BytesMut
Splits the buffer into two at the given index.
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more bytes to be written in
the given ByteBuf
. The ByteBuf
may reserve more space to avoid
frequent reallocations.
fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional more bytes to be
written in the given ByteBuf
. Does nothing if the capacity is already
sufficient.
Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.
fn get_ref(&self) -> &BytesMut
Gets a reference to the underlying BytesMut
fn into_inner(self) -> BytesMut
Unwraps the ByteBuf
, returning the underlying BytesMut
Trait Implementations
impl Buf for ByteBuf
[src]
fn remaining(&self) -> usize
Returns the number of bytes that can be accessed from the Buf
fn bytes(&self) -> &[u8]
Returns a slice starting at the current Buf position and of length between 0 and Buf::remaining()
. Read more
fn advance(&mut self, cnt: usize)
Advance the internal cursor of the Buf
fn copy_to_slice(&mut self, dst: &mut [u8])
Copies bytes from the Buf
into the given slice and advance the cursor by the number of bytes copied. Read more
fn has_remaining(&self) -> bool
Returns true if there are any more bytes to consume
fn copy_to<S: Sink + ?Sized>(&mut self, dst: &mut S) where Self: Sized
Copies bytes from self
into dst
Read more
fn peek_u8(&self) -> Option<u8>
Gets an unsigned 8 bit integer from the Buf
without advancing the buffer cursor Read more
fn get_u8(&mut self) -> u8
Gets an unsigned 8 bit integer from the Buf
.
fn get_i8(&mut self) -> i8
Gets a signed 8 bit integer from the Buf
.
fn get_u16<T: ByteOrder>(&mut self) -> u16
Gets an unsigned 16 bit integer from the Buf
fn get_i16<T: ByteOrder>(&mut self) -> i16
Gets a signed 16 bit integer from the Buf
fn get_u32<T: ByteOrder>(&mut self) -> u32
Gets an unsigned 32 bit integer from the Buf
fn get_i32<T: ByteOrder>(&mut self) -> i32
Gets a signed 32 bit integer from the Buf
fn get_u64<T: ByteOrder>(&mut self) -> u64
Gets an unsigned 64 bit integer from the Buf
fn get_i64<T: ByteOrder>(&mut self) -> i64
Gets a signed 64 bit integer from the Buf
fn get_uint<T: ByteOrder>(&mut self, nbytes: usize) -> u64
Gets an unsigned n-bytes integer from the Buf
fn get_int<T: ByteOrder>(&mut self, nbytes: usize) -> i64
Gets a signed n-bytes integer from the Buf
fn get_f32<T: ByteOrder>(&mut self) -> f32
Gets a IEEE754 single-precision (4 bytes) floating point number from the Buf
Read more
fn get_f64<T: ByteOrder>(&mut self) -> f64
Gets a IEEE754 double-precision (8 bytes) floating point number from the Buf
Read more
fn by_ref(&mut self) -> &mut Self where Self: Sized
Creates a "by reference" adaptor for this instance of Buf
fn take(self, limit: usize) -> Take<Self> where Self: Sized
Create an adapter which will limit at most limit
bytes from it.
fn reader(self) -> Reader<Self> where Self: Sized
Return a Reader
for the value. Allows using a Buf
as an io::Read
impl BufMut for ByteBuf
[src]
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()
. Read more
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. Read more
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
Read more
fn put_str(&mut self, src: &str)
Writes the given string into self. Read more
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. Read more
fn put_int<T: ByteOrder>(&mut self, n: i64, nbytes: usize)
Writes a signed n-bytes integer to the BufMut. Read more
fn put_f32<T: ByteOrder>(&mut self, n: f32)
Writes a IEEE754 single-precision (4 bytes) floating point number to the BufMut. Read more
fn put_f64<T: ByteOrder>(&mut self, n: f64)
Writes a IEEE754 double-precision (8 bytes) floating point number to the BufMut. Read more
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
Read more
impl Debug for ByteBuf
[src]
impl Write for ByteBuf
[src]
fn write_str(&mut self, s: &str) -> Result
Writes a slice of bytes into this writer, returning whether the write succeeded. Read more
fn write_fmt(&mut self, args: Arguments) -> Result
Glue for usage of the write!
macro with implementors of this trait. Read more
fn write_char(&mut self, c: char) -> Result<(), Error>
1.1.0
Writes a char
into this writer, returning whether the write succeeded. Read more