Buffer

Trait Buffer 

Source
pub trait Buffer {
    // Required methods
    fn new() -> Self
       where Self: Sized;
    fn with_capacity(capacity: usize) -> Self
       where Self: Sized;
    fn consume(&mut self, rng: RangeTo<usize>);
    fn clear(&mut self);
    fn resize(&mut self, len: usize) -> Result<()>;
    fn truncate(&mut self, len: usize);
    fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>;
    fn as_slice(&self) -> &[u8] ;
    fn as_mut_slice(&mut self) -> &mut [u8] ;
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;
    fn capacity(&self) -> usize;
}
Expand description

A trait for types that can be used as a buffer in the Peekable and AsyncPeekable reader.

Required Methods§

Source

fn new() -> Self
where Self: Sized,

Create a new empty buffer.

Source

fn with_capacity(capacity: usize) -> Self
where Self: Sized,

Create a new buffer with the specified capacity.

Source

fn consume(&mut self, rng: RangeTo<usize>)

Consume the range from the buffer, the remaining elements are shifted to the left.

Source

fn clear(&mut self)

Remove all elements from the buffer.

Source

fn resize(&mut self, len: usize) -> Result<()>

Resizes the buffer so that its length is equal to len.

Source

fn truncate(&mut self, len: usize)

Shorten the buffer, keeping the first len elements and dropping the rest.

Source

fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>

Copy elements from a slice and append them to the buffer.

Source

fn as_slice(&self) -> &[u8]

Returns a slice of the buffer.

Source

fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice of the buffer.

Source

fn len(&self) -> usize

Returns the length of the buffer.

Source

fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

fn capacity(&self) -> usize

Returns the capacity of the buffer.

Implementations on Foreign Types§

Source§

impl Buffer for Vec<u8>

Source§

fn new() -> Self

Source§

fn with_capacity(capacity: usize) -> Self

Source§

fn consume(&mut self, rng: RangeTo<usize>)

Source§

fn clear(&mut self)

Source§

fn resize(&mut self, len: usize) -> Result<()>

Source§

fn truncate(&mut self, len: usize)

Source§

fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>

Source§

fn as_slice(&self) -> &[u8]

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn capacity(&self) -> usize

Source§

impl<A> Buffer for SmallVec<A>
where A: Array<Item = u8>,

Available on crate feature smallvec only.
Source§

fn new() -> Self
where Self: Sized,

Source§

fn with_capacity(capacity: usize) -> Self
where Self: Sized,

Source§

fn consume(&mut self, rng: RangeTo<usize>)

Source§

fn clear(&mut self)

Source§

fn resize(&mut self, len: usize) -> Result<()>

Source§

fn truncate(&mut self, len: usize)

Source§

fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>

Source§

fn as_slice(&self) -> &[u8]

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn capacity(&self) -> usize

Source§

impl<A: Array<Item = u8>> Buffer for TinyVec<A>

Available on crate feature tinyvec only.
Source§

fn new() -> Self
where Self: Sized,

Source§

fn with_capacity(capacity: usize) -> Self
where Self: Sized,

Source§

fn consume(&mut self, rng: RangeTo<usize>)

Source§

fn clear(&mut self)

Source§

fn resize(&mut self, len: usize) -> Result<()>

Source§

fn truncate(&mut self, len: usize)

Source§

fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>

Source§

fn as_slice(&self) -> &[u8]

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn capacity(&self) -> usize

Implementors§