struct U64UnalignedSlice<'a> {
ptr: *mut u64,
len: usize,
_marker: PhantomData<&'a u8>,
}Expand description
Centralized structure to handle a mutable u8 slice as a mutable u64 pointer.
Handle the following:
- the lifetime is correct
- we read/write within the bounds
- We read and write using unaligned
This does not deallocate the underlying pointer when dropped
This is the only place that uses unsafe code to read and write unaligned
Fields§
§ptr: *mut u64Pointer to the start of the u64 data
We are using raw pointer as the data came from a u8 slice so we need to read and write unaligned
len: usizeNumber of u64 elements
_marker: PhantomData<&'a u8>Marker to tie the lifetime of the pointer to the lifetime of the u8 slice
Implementations§
Source§impl<'a> U64UnalignedSlice<'a>
impl<'a> U64UnalignedSlice<'a>
Sourcefn split(
buffer: &'a mut [u8],
offset_in_bits: usize,
len_in_bits: usize,
) -> (Self, &'a mut [u8])
fn split( buffer: &'a mut [u8], offset_in_bits: usize, len_in_bits: usize, ) -> (Self, &'a mut [u8])
Create a new U64UnalignedSlice from a &mut [u8] buffer
return the U64UnalignedSlice and slice of bytes that are not part of the u64 chunks (guaranteed to be less than 8 bytes)
fn len(&self) -> usize
Sourcefn zip_modify(
self,
zip_iter: impl ExactSizeIterator<Item = u64>,
map: impl FnMut(u64, u64) -> u64,
)
fn zip_modify( self, zip_iter: impl ExactSizeIterator<Item = u64>, map: impl FnMut(u64, u64) -> u64, )
Modify the underlying u64 data in place using a binary operation with another iterator.
Sourceunsafe fn apply_bin_op(&mut self, right: u64, map: impl FnMut(u64, u64) -> u64)
unsafe fn apply_bin_op(&mut self, right: u64, map: impl FnMut(u64, u64) -> u64)
Centralized function to correctly read the current u64 value and write back the result
§SAFETY
the caller must ensure that the pointer is valid for reads and writes
Sourcefn apply_unary_op(self, map: impl FnMut(u64) -> u64)
fn apply_unary_op(self, map: impl FnMut(u64) -> u64)
Modify the underlying u64 data in place using a unary operation.