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]) -> MutPtrByteSlice<'a>
pub unsafe fn new(slice: *mut [u8]) -> MutPtrByteSlice<'a>
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>(&self) -> Option<T>
pub fn read<T>(&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>(&mut self, val: T) -> Option<()>
pub fn write<T>(&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 zero_no_rfo(&mut self)
pub fn zero_no_rfo(&mut self)
Informs the memory subsystem that the slice is about to be completely overwritten,
optimizing cache line allocation and avoiding Read-For-Ownership (RFO) DRAM reads on
supported architectures (such as ARM64 via dc zva).
§Semantics
- On architectures where supported (e.g. ARM64
dc zva), this pre-allocates cache lines in L1/L2 and zeroes them without issuing Write-Allocate DRAM reads. - On other architectures, this is a no-op.
- Callers must not rely on existing data being preserved, nor must they rely on the buffer being zeroed.
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>) -> MutPtrByteSlice<'a>
pub fn subslice_mut(&mut self, range: Range<usize>) -> MutPtrByteSlice<'a>
Sourcepub fn split_at_mut(
self,
mid: usize,
) -> (MutPtrByteSlice<'a>, MutPtrByteSlice<'a>)
pub fn split_at_mut( self, mid: usize, ) -> (MutPtrByteSlice<'a>, MutPtrByteSlice<'a>)
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.
Sourcepub fn append_to(&self, vec: &mut Vec<u8>)
pub fn append_to(&self, vec: &mut Vec<u8>)
Appends the contents of this slice to the given vector, expanding its capacity if needed. Bypasses zero-initialization using raw pointer copies.
Sourcepub fn iter_as_mut<T>(&mut self) -> IterAsMut<'_, T>
pub fn iter_as_mut<T>(&mut self) -> IterAsMut<'_, T>
Returns an iterator over mutable typed elements T.
§Panics
Panics if the slice is not aligned to T or if its length in bytes is not a multiple of
size_of::<T>().
Sourcepub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_>
pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_>
Returns an iterator over mutable byte chunks of up to chunk_size bytes.
§Panics
Panics if chunk_size is 0.