Skip to main content

MutPtrByteSlice

Struct MutPtrByteSlice 

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

Source

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.

Source

pub fn len(&self) -> usize

Returns the length of the slice in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the slice has a length of 0.

Source

pub fn read<T>(&self) -> Option<T>
where T: Copy + FromBytes,

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.

Source

pub fn write<T>(&mut self, val: T) -> Option<()>
where T: Copy + FromBytes,

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.

Source

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().

Source

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.

Source

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.

Source

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

pub fn fill(&mut self, val: u8)

Fills the slice with the given byte value.

Source

pub fn as_ptr_slice(&self) -> PtrByteSlice<'_>

Returns a read-only view of this slice.

Source

pub fn subslice_mut(&mut self, range: Range<usize>) -> MutPtrByteSlice<'a>

Returns a mutable subslice of this pointer slice.

§Panics

Panics if the range is out of bounds.

Source

pub fn split_at_mut( self, mid: usize, ) -> (MutPtrByteSlice<'a>, MutPtrByteSlice<'a>)

Splits the slice into two at the given index.

§Panics

Panics if mid is out of bounds.

Source

pub fn as_raw_mut_slice_ptr(&self) -> *mut [u8]

Returns the raw mutable pointer to the slice.

Source

pub fn as_ptr(&self) -> *const u8

Returns a raw pointer to the start of the slice.

Source

pub fn as_mut_ptr(&self) -> *mut u8

Returns a raw mutable pointer to the start of the slice.

Source

pub fn reborrow(&mut self) -> MutPtrByteSlice<'_>

Reborrows the mutable slice with a shorter lifetime.

Source

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.

Source

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.

Source

pub fn iter_as_mut<T>(&mut self) -> IterAsMut<'_, T>
where T: Copy + FromBytes,

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>().

Source

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.

Source

pub fn writer(self) -> Writer<'a>

Returns an io::Write adapter for this slice.

Trait Implementations§

Source§

impl<'a> Debug for MutPtrByteSlice<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a mut Vec<u8>> for MutPtrByteSlice<'a>

Source§

fn from(vec: &'a mut Vec<u8>) -> MutPtrByteSlice<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a mut [u8]> for MutPtrByteSlice<'a>

Source§

fn from(slice: &'a mut [u8]) -> MutPtrByteSlice<'a>

Converts to this type from the input type.
Source§

impl Send for MutPtrByteSlice<'_>

Source§

impl Sync for MutPtrByteSlice<'_>

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for MutPtrByteSlice<'a>

§

impl<'a> Freeze for MutPtrByteSlice<'a>

§

impl<'a> RefUnwindSafe for MutPtrByteSlice<'a>

§

impl<'a> Unpin for MutPtrByteSlice<'a>

§

impl<'a> UnsafeUnpin for MutPtrByteSlice<'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
§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V