pub struct MutPtrByteSlice<'a> { /* private fields */ }Expand description
A mutable view of a raw pointer byte slice, providing a safe API.
Implementations§
Source§impl<'a> MutPtrByteSlice<'a>
impl<'a> MutPtrByteSlice<'a>
Sourcepub unsafe fn new(slice: *mut [u8]) -> Self
pub unsafe fn new(slice: *mut [u8]) -> Self
Creates a new MutPtrByteSlice from a raw mutable pointer to a byte slice.
§Safety
The caller must ensure that slice is valid for reads and writes for the lifetime 'a.
Sourcepub fn read<T: Copy + FromBytes>(&self) -> Option<T>
pub fn read<T: Copy + FromBytes>(&self) -> Option<T>
Reads a copy of a value of type T from the start of the slice.
The read is performed unaligned, so the slice does not need to be aligned to T.
Sourcepub fn write<T: Copy + FromBytes>(&mut self, val: T) -> Option<()>
pub fn write<T: Copy + FromBytes>(&mut self, val: T) -> Option<()>
Writes a value of type T to the start of the slice.
The write is performed unaligned, so the slice does not need to be aligned to T.
Sourcepub fn copy_to_slice(&self, dest: &mut [u8])
pub fn copy_to_slice(&self, dest: &mut [u8])
Copies the contents of this slice into a safe Rust mutable slice.
§Panics
Panics if dest is smaller than self.len().
Sourcepub fn copy_from_ptr_slice(&mut self, src: PtrByteSlice<'_>)
pub fn copy_from_ptr_slice(&mut self, src: PtrByteSlice<'_>)
Copies the contents of another read-only pointer slice into this mutable slice.
§Panics
Panics if the lengths of the slices do not match.
Sourcepub fn copy_from_slice(&mut self, src: &[u8])
pub fn copy_from_slice(&mut self, src: &[u8])
Copies the contents of a standard safe slice into this mutable slice.
§Panics
Panics if the lengths of the slices do not match.
Sourcepub fn as_ptr_slice(&self) -> PtrByteSlice<'_> ⓘ
pub fn as_ptr_slice(&self) -> PtrByteSlice<'_> ⓘ
Returns a read-only view of this slice.
Sourcepub fn subslice_mut(&mut self, range: Range<usize>) -> Self
pub fn subslice_mut(&mut self, range: Range<usize>) -> Self
Sourcepub fn split_at_mut(self, mid: usize) -> (Self, Self)
pub fn split_at_mut(self, mid: usize) -> (Self, Self)
Sourcepub fn as_raw_mut_slice_ptr(&self) -> *mut [u8]
pub fn as_raw_mut_slice_ptr(&self) -> *mut [u8]
Returns the raw mutable pointer to the slice.
Sourcepub fn as_mut_ptr(&self) -> *mut u8
pub fn as_mut_ptr(&self) -> *mut u8
Returns a raw mutable pointer to the start of the slice.
Sourcepub fn reborrow(&mut self) -> MutPtrByteSlice<'_>
pub fn reborrow(&mut self) -> MutPtrByteSlice<'_>
Reborrows the mutable slice with a shorter lifetime.
Sourcepub fn to_vec(&self) -> Vec<u8> ⓘ
pub fn to_vec(&self) -> Vec<u8> ⓘ
Allocates a new heap Vector and copies the contents into it. Bypasses zero-initialization using raw pointer copies.