U64UnalignedSlice

Struct U64UnalignedSlice 

Source
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:

  1. the lifetime is correct
  2. we read/write within the bounds
  3. 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 u64

Pointer 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: usize

Number 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>

Source

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)

Source

fn len(&self) -> usize

Source

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.

Source

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

Source

fn apply_unary_op(self, map: impl FnMut(u64) -> u64)

Modify the underlying u64 data in place using a unary operation.

Auto Trait Implementations§

§

impl<'a> Freeze for U64UnalignedSlice<'a>

§

impl<'a> RefUnwindSafe for U64UnalignedSlice<'a>

§

impl<'a> !Send for U64UnalignedSlice<'a>

§

impl<'a> !Sync for U64UnalignedSlice<'a>

§

impl<'a> Unpin for U64UnalignedSlice<'a>

§

impl<'a> UnwindSafe for U64UnalignedSlice<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.