pub struct PtrBuffer { /* private fields */ }Expand description
A Buffer object backed by a pointer/size pair. Use this buffer type
when accessing unowned memory or arbitrary allocated memory.
Implementations
sourceimpl PtrBuffer
impl PtrBuffer
sourcepub fn new(pointer: *const u8, size: usize) -> Self
pub fn new(pointer: *const u8, size: usize) -> Self
Create a new buffer object with a given pointer and size. Just make sure the pointer outlives the object and not the other way around.
sourcepub fn set_pointer(&mut self, pointer: *const u8)
pub fn set_pointer(&mut self, pointer: *const u8)
Set the new pointer of this buffer.
Trait Implementations
sourceimpl Buffer for PtrBuffer
impl Buffer for PtrBuffer
sourcefn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
Get the PtrBuffer object as a mutable pointer.
sourcefn as_slice(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
fn as_slice(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get the PtrBuffer object as a slice.
sourcefn as_mut_slice(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
fn as_mut_slice(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get the PtrBuffer 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>(&self, offset: usize) -> Result<&T, Error>
fn get_ref<T>(&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
sourcefn get_mut_ref<T>(&mut self, offset: usize) -> Result<&mut T, Error>
fn get_mut_ref<T>(&mut self, offset: usize) -> Result<&mut T, Error>
Get a mutable reference to a given object within the buffer. See Buffer::get_ref.
sourcefn make_mut_ref<T>(&mut self, data: &T) -> Result<&mut T, Error>
fn make_mut_ref<T>(&mut self, data: &T) -> Result<&mut T, Error>
Convert a given reference to a mutable reference within the buffer. Read more
sourcefn get_slice_ref<T>(&self, offset: usize, size: usize) -> Result<&[T], Error>
fn get_slice_ref<T>(&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
sourcefn get_mut_slice_ref<T>(
&mut self,
offset: usize,
size: usize
) -> Result<&mut [T], Error>
fn get_mut_slice_ref<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.
See Buffer::get_slice_ref. 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>(&mut self, offset: usize, data: &T) -> Result<(), Error>
fn write_ref<T>(&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>(&mut self, offset: usize, data: &[T]) -> Result<(), Error>
fn write_slice_ref<T>(&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>(&mut self, data: &T) -> Result<(), Error>
fn start_with_ref<T>(&mut self, data: &T) -> Result<(), Error>
Start the buffer with the given reference data. Read more
sourcefn start_with_slice_ref<T>(&mut self, data: &[T]) -> Result<(), Error>
fn start_with_slice_ref<T>(&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>(&mut self, data: &T) -> Result<(), Error>
fn end_with_ref<T>(&mut self, data: &T) -> Result<(), Error>
End the buffer with the given reference data. Read more
sourcefn end_with_slice_ref<T>(&mut self, data: &[T]) -> Result<(), Error>
fn end_with_slice_ref<T>(&mut self, data: &[T]) -> Result<(), Error>
End the buffer with the given slice reference data. Read more
sourcefn search_ref<'a, T>(&'a self, data: &T) -> Result<BufferSearchIter<'a>, Error>
fn search_ref<'a, T>(&'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>(
&'a self,
data: &[T]
) -> Result<BufferSearchIter<'a>, Error>
fn search_slice_ref<'a, T>(
&'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>(&self, data: &T) -> bool
fn contains_ref<T>(&self, data: &T) -> bool
Check if this buffer contains the following object of type T.
sourcefn contains_slice_ref<T>(&self, data: &[T]) -> bool
fn contains_slice_ref<T>(&self, data: &[T]) -> bool
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 PtrBuffer
impl IntoIterator for PtrBuffer
impl Copy for PtrBuffer
impl Eq for PtrBuffer
impl StructuralEq for PtrBuffer
Auto Trait Implementations
impl RefUnwindSafe for PtrBuffer
impl !Send for PtrBuffer
impl !Sync for PtrBuffer
impl Unpin for PtrBuffer
impl UnwindSafe for PtrBuffer
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