pub struct VecBuffer { /* private fields */ }Expand description
An owned-data Buffer object.
Implementations
sourceimpl VecBuffer
impl VecBuffer
sourcepub fn from_data<B: AsRef<[u8]>>(data: B) -> Self
pub fn from_data<B: AsRef<[u8]>>(data: B) -> Self
Create a new VecBuffer object with initialization data.
sourcepub fn from_file<P: AsRef<Path>>(filename: P) -> Result<Self, Error>
pub fn from_file<P: AsRef<Path>>(filename: P) -> Result<Self, Error>
Create a new VecBuffer from the given file data.
sourcepub fn with_initial_size(size: usize) -> Self
pub fn with_initial_size(size: usize) -> Self
Create a new VecBuffer with a given starting size. This will zero out the
buffer on initialization.
sourcepub fn as_ptr_buffer(&self) -> PtrBuffer
pub fn as_ptr_buffer(&self) -> PtrBuffer
Create a PtrBuffer object from this VecBuffer object.
sourcepub fn append<B: AsRef<[u8]>>(&mut self, data: B)
pub fn append<B: AsRef<[u8]>>(&mut self, data: B)
Appends the given data to the end of the buffer. This resizes and expands the underlying vector.
sourcepub fn append_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
pub fn append_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
Appends the given reference to the end of the buffer. This resizes and expands the underlying vector.
sourcepub fn append_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
pub fn append_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
Appends the given slice reference to the end of the buffer. This resizes and expands the underlying vector.
sourcepub fn insert(&mut self, offset: usize, element: u8)
pub fn insert(&mut self, offset: usize, element: u8)
Insert a given element at the given offset, expanding the vector by one. See Vec::insert.
sourcepub fn remove(&mut self, offset: usize)
pub fn remove(&mut self, offset: usize)
Remove a given element at the given offset, shrinking the vector by one. See Vec::remove.
sourcepub fn retain<F>(&mut self, f: F) where
F: FnMut(&u8) -> bool,
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&u8) -> bool,
Retains only the elements specified by the predicate. See Vec::retain.
sourcepub fn split_off(&mut self, at: usize) -> Self
pub fn split_off(&mut self, at: usize) -> Self
Split off into another VecBuffer instance at the given midpoint. See Vec::split_off.
sourcepub fn resize_with<F>(&mut self, new_len: usize, f: F) where
F: FnMut() -> u8,
pub fn resize_with<F>(&mut self, new_len: usize, f: F) where
F: FnMut() -> u8,
Resize the buffer to new size, filling with the given closure f. See Vec::resize_with.
sourcepub fn resize(&mut self, new_len: usize, value: u8)
pub fn resize(&mut self, new_len: usize, value: u8)
Resize the given buffer and fill the void with the given value. See Vec::resize.
sourcepub fn dedup(&mut self)
pub fn dedup(&mut self)
Deduplicate the values in this buffer. See Vec::dedup.
Trait Implementations
sourceimpl Buffer for VecBuffer
impl Buffer for VecBuffer
sourcefn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
Get the VecBuffer object as a mutable pointer.
sourcefn as_slice(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
fn as_slice(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get the VecBuffer object as a slice.
sourcefn as_mut_slice(&mut self) -> &mut [u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
fn as_mut_slice(&mut self) -> &mut [u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get the VecBuffer object as a mutable slice.
sourcefn as_ptr_range(&self) -> Range<*const u8>
fn as_ptr_range(&self) -> Range<*const u8>
Get a pointer range of this buffer. See slice::as_ptr_range for more details.
sourcefn as_mut_ptr_range(&mut self) -> Range<*mut u8>
fn as_mut_ptr_range(&mut self) -> Range<*mut u8>
Get a mutable pointer range of this buffer. See slice::as_mut_ptr_range for more details.
sourcefn validate_ptr(&self, ptr: *const u8) -> bool
fn validate_ptr(&self, ptr: *const u8) -> bool
Validate that the given pointer object is within the range of this buffer.
sourcefn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>
fn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>
Convert a pointer to an offset into the buffer. Read more
sourcefn ref_to_offset<T>(&self, data: &T) -> Result<usize, Error>
fn ref_to_offset<T>(&self, data: &T) -> Result<usize, Error>
Convert a given reference to an object into an offset into the buffer. Read more
sourcefn swap(&mut self, a: usize, b: usize)
fn swap(&mut self, a: usize, b: usize)
Swap two bytes at the given offsets. This panics if the offsets are out of bounds. See slice::swap
for more details. Read more
sourcefn reverse(&mut self)
fn reverse(&mut self)
Reverse the buffer. See slice::reverse for more details.
sourcefn iter(&self) -> BufferIter<'_>ⓘNotable traits for BufferIter<'a>impl<'a> Iterator for BufferIter<'a> type Item = &'a u8;
fn iter(&self) -> BufferIter<'_>ⓘNotable traits for BufferIter<'a>impl<'a> Iterator for BufferIter<'a> type Item = &'a u8;
Return an iterator object (BufferIter) into the buffer.
sourcefn iter_mut(&mut self) -> BufferIterMut<'_>ⓘNotable traits for BufferIterMut<'a>impl<'a> Iterator for BufferIterMut<'a> type Item = &'a mut u8;
fn iter_mut(&mut self) -> BufferIterMut<'_>ⓘNotable traits for BufferIterMut<'a>impl<'a> Iterator for BufferIterMut<'a> type Item = &'a mut u8;
Return a mutable iterator object (BufferIterMut) into the buffer.
sourcefn get<I: SliceIndex<[u8]>>(&self, index: I) -> Option<&I::Output>
fn get<I: SliceIndex<[u8]>>(&self, index: I) -> Option<&I::Output>
Get the given byte or range of bytes from the buffer. See slice::get for more details.
sourcefn get_mut<I: SliceIndex<[u8]>>(&mut self, index: I) -> Option<&mut I::Output>
fn get_mut<I: SliceIndex<[u8]>>(&mut self, index: I) -> Option<&mut I::Output>
Get the given byte or range of bytes from the buffer as mutable. See slice::get_mut for more details.
sourcefn get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>
fn get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>
Get a reference to a given object within the buffer. Typically the main interface by which objects are retrieved. Read more
sourceunsafe fn get_ref_unaligned<T>(&self, offset: usize) -> Result<&T, Error>
unsafe fn get_ref_unaligned<T>(&self, offset: usize) -> Result<&T, Error>
Get a reference to a given object within the buffer, but in an unaligned way. Read more
sourceunsafe fn force_get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>
unsafe fn force_get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>
Get a reference regardless of potential alignment issues. Read more
sourcefn get_mut_ref<T: Castable>(&mut self, offset: usize) -> Result<&mut T, Error>
fn get_mut_ref<T: Castable>(&mut self, offset: usize) -> Result<&mut T, Error>
Get a mutable reference to a given object within the buffer. See Buffer::get_ref.
sourceunsafe fn get_mut_ref_unaligned<T>(
&mut self,
offset: usize
) -> Result<&mut T, Error>
unsafe fn get_mut_ref_unaligned<T>(
&mut self,
offset: usize
) -> Result<&mut T, Error>
Get a mutable reference to a given object within the buffer, but in an unaligned way. Read more
sourceunsafe fn force_get_mut_ref<T: Castable>(
&mut self,
offset: usize
) -> Result<&mut T, Error>
unsafe fn force_get_mut_ref<T: Castable>(
&mut self,
offset: usize
) -> Result<&mut T, Error>
Get a mutable reference regardless of potential alignment issues. Read more
sourcefn make_mut_ref<T: Castable>(&mut self, data: &T) -> Result<&mut T, Error>
fn make_mut_ref<T: Castable>(&mut self, data: &T) -> Result<&mut T, Error>
Convert a given reference to a mutable reference within the buffer. Read more
sourceunsafe fn make_mut_ref_unaligned<T>(
&mut self,
data: &T
) -> Result<&mut T, Error>
unsafe fn make_mut_ref_unaligned<T>(
&mut self,
data: &T
) -> Result<&mut T, Error>
Convert a given reference to a mutable reference without alignment guarantees. Read more
sourceunsafe fn force_make_mut_ref<T: Castable>(
&mut self,
data: &T
) -> Result<&mut T, Error>
unsafe fn force_make_mut_ref<T: Castable>(
&mut self,
data: &T
) -> Result<&mut T, Error>
Convert an object to a mutable reference regardless of potential alignment issues. Read more
sourcefn get_slice_ref<T: Castable>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
fn get_slice_ref<T: Castable>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
Gets a slice reference of type T at the given offset with the given size. Read more
sourceunsafe fn get_slice_ref_unaligned<T>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
unsafe fn get_slice_ref_unaligned<T>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
Gets a slice ref of type T at the given offset regardless of potential alignment issues. Read more
sourceunsafe fn force_get_slice_ref<T: Castable>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
unsafe fn force_get_slice_ref<T: Castable>(
&self,
offset: usize,
size: usize
) -> Result<&[T], Error>
Get a slice reference regardless of potential alignment issues. Read more
sourcefn get_mut_slice_ref<T: Castable>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
fn get_mut_slice_ref<T: Castable>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
Gets a mutable slice reference of type T at the given offset with the given size.
See Buffer::get_slice_ref. Read more
sourceunsafe fn get_mut_slice_ref_unaligned<T>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
unsafe fn get_mut_slice_ref_unaligned<T>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
Gets a mutable slice reference of type T at the given offset with the given size,
but without alignment checking. See Buffer::get_slice_ref_unaligned. Read more
sourceunsafe fn force_get_mut_slice_ref<T: Castable>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
unsafe fn force_get_mut_slice_ref<T: Castable>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
Get a mutable slice reference regardless of potential alignment issues. Read more
sourceunsafe fn make_mut_slice_ref_unaligned<T>(
&mut self,
data: &[T]
) -> Result<&mut [T], Error>
unsafe fn make_mut_slice_ref_unaligned<T>(
&mut self,
data: &[T]
) -> Result<&mut [T], Error>
Convert a given slice reference to a mutable slice reference without alignment guarantees. Read more
sourceunsafe fn force_make_mut_slice_ref<T: Castable>(
&mut self,
data: &[T]
) -> Result<&mut [T], Error>
unsafe fn force_make_mut_slice_ref<T: Castable>(
&mut self,
data: &[T]
) -> Result<&mut [T], Error>
Convert an object to a mutable reference regardless of potential alignment issues. Read more
sourcefn read(&self, offset: usize, size: usize) -> Result<&[u8], Error>
fn read(&self, offset: usize, size: usize) -> Result<&[u8], Error>
Read an arbitrary size amount of bytes from the given offset. Read more
sourcefn read_mut(&mut self, offset: usize, size: usize) -> Result<&mut [u8], Error>
fn read_mut(&mut self, offset: usize, size: usize) -> Result<&mut [u8], Error>
Read an arbitrary size amount of bytes from the given offset, but mutable. Read more
sourcefn write_ref<T: Castable>(
&mut self,
offset: usize,
data: &T
) -> Result<(), Error>
fn write_ref<T: Castable>(
&mut self,
offset: usize,
data: &T
) -> Result<(), Error>
Write a given object of type T to the given buffer at the given offset. Read more
sourcefn write_slice_ref<T: Castable>(
&mut self,
offset: usize,
data: &[T]
) -> Result<(), Error>
fn write_slice_ref<T: Castable>(
&mut self,
offset: usize,
data: &[T]
) -> Result<(), Error>
Write a given slice object of type T to the given buffer at the given offset. Read more
sourcefn start_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
fn start_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
Start the buffer object with the given byte data. Read more
sourcefn start_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
fn start_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
Start the buffer with the given reference data. Read more
sourcefn start_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
fn start_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
Start the buffer with the given slice reference data. Read more
sourcefn end_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
fn end_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
End the buffer object with the given byte data. Read more
sourcefn end_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
fn end_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>
End the buffer with the given reference data. Read more
sourcefn end_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
fn end_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>
End the buffer with the given slice reference data. Read more
sourcefn search_ref<'a, T: Castable>(
&'a self,
data: &T
) -> Result<BufferSearchIter<'a>, Error>
fn search_ref<'a, T: Castable>(
&'a self,
data: &T
) -> Result<BufferSearchIter<'a>, Error>
Search for the following reference of type T. This converts the object into a u8 slice.
See Buffer::search. Read more
sourcefn search_slice_ref<'a, T: Castable>(
&'a self,
data: &[T]
) -> Result<BufferSearchIter<'a>, Error>
fn search_slice_ref<'a, T: Castable>(
&'a self,
data: &[T]
) -> Result<BufferSearchIter<'a>, Error>
Search for the following slice reference of type T. This converts the slice into a u8 slice.
See Buffer::search. Read more
sourcefn contains_ref<T: Castable>(&self, data: &T) -> Result<bool, Error>
fn contains_ref<T: Castable>(&self, data: &T) -> Result<bool, Error>
Check if this buffer contains the following object of type T.
sourcefn contains_slice_ref<T: Castable>(&self, data: &[T]) -> Result<bool, Error>
fn contains_slice_ref<T: Castable>(&self, data: &[T]) -> Result<bool, Error>
Check if this buffer contains the following slice of type T.
sourcefn starts_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
fn starts_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
Check if this buffer starts with the byte sequence needle. See slice::starts_with.
sourcefn ends_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
fn ends_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
Check if this buffer ends with the byte sequence needle. See slice::ends_with.
sourcefn rotate_left(&mut self, mid: usize)
fn rotate_left(&mut self, mid: usize)
Rotate the buffer left at midpoint mid. See slice::rotate_left.
sourcefn rotate_right(&mut self, mid: usize)
fn rotate_right(&mut self, mid: usize)
Rotate the buffer right at midpoint mid. See slice::rotate_right.
sourcefn fill(&mut self, value: u8)
fn fill(&mut self, value: u8)
Fill the given buffer with the given value. See slice::fill.
sourcefn fill_with<F>(&mut self, f: F) where
F: FnMut() -> u8,
fn fill_with<F>(&mut self, f: F) where
F: FnMut() -> u8,
Fill the given buffer with the given closure f. See slice::fill_with.
sourcefn copy_within<R>(&mut self, src: R, dest: usize) where
R: RangeBounds<usize>,
fn copy_within<R>(&mut self, src: R, dest: usize) where
R: RangeBounds<usize>,
Copy from within the given buffer. See slice::copy_within.
sourcefn is_ascii(&self) -> bool
fn is_ascii(&self) -> bool
Check if this buffer is ASCII. See slice::is_ascii.
sourcefn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
Check if this buffer is equal while ignoring case of letters. See slice::eq_ignore_ascii_case.
sourcefn make_ascii_uppercase(&mut self)
fn make_ascii_uppercase(&mut self)
Make this buffer ASCII uppercase. See slice::make_ascii_uppercase.
sourcefn make_ascii_lowercase(&mut self)
fn make_ascii_lowercase(&mut self)
Make this buffer ASCII lowercase. See slice::make_ascii_lowercase.
sourcefn sort(&mut self)
fn sort(&mut self)
Sort this buffer. See slice::sort.
sourcefn sort_by<F>(&mut self, compare: F) where
F: FnMut(&u8, &u8) -> Ordering,
fn sort_by<F>(&mut self, compare: F) where
F: FnMut(&u8, &u8) -> Ordering,
Sort by the given closure comparing each individual byte. See slice::sort_by.
sourcefn sort_by_key<K, F>(&mut self, f: F) where
F: FnMut(&u8) -> K,
K: Ord,
fn sort_by_key<K, F>(&mut self, f: F) where
F: FnMut(&u8) -> K,
K: Ord,
Sorts the slice with a key extraction function. See slice::sort_by_key.
sourceimpl IntoIterator for VecBuffer
impl IntoIterator for VecBuffer
impl Eq for VecBuffer
impl StructuralEq for VecBuffer
Auto Trait Implementations
impl RefUnwindSafe for VecBuffer
impl Send for VecBuffer
impl Sync for VecBuffer
impl Unpin for VecBuffer
impl UnwindSafe for VecBuffer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more