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§
Sourcefn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
fn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
Create a new buffer with the specified capacity.
Sourcefn consume(&mut self, rng: RangeTo<usize>)
fn consume(&mut self, rng: RangeTo<usize>)
Consume the range from the buffer, the remaining elements are shifted to the left.
Sourcefn resize(&mut self, len: usize) -> Result<()>
fn resize(&mut self, len: usize) -> Result<()>
Resizes the buffer so that its length is equal to len.
Sourcefn truncate(&mut self, len: usize)
fn truncate(&mut self, len: usize)
Shorten the buffer, keeping the first len elements and dropping the rest.
Sourcefn extend_from_slice(&mut self, other: &[u8]) -> Result<()>
fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>
Copy elements from a slice and append them to the buffer.
Sourcefn as_mut_slice(&mut self) -> &mut [u8] ⓘ
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice of the buffer.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Buffer for Vec<u8>
impl Buffer for Vec<u8>
fn new() -> Self
fn with_capacity(capacity: usize) -> Self
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
Source§impl<A: Array<Item = u8>> Buffer for TinyVec<A>
Available on crate feature tinyvec only.
impl<A: Array<Item = u8>> Buffer for TinyVec<A>
Available on crate feature
tinyvec only.fn new() -> Selfwhere
Self: Sized,
fn with_capacity(capacity: usize) -> Selfwhere
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
Source§impl<A> Buffer for SmallVec<A>
Available on crate feature smallvec only.
impl<A> Buffer for SmallVec<A>
Available on crate feature
smallvec only.