Skip to main content

SliceMutUnchecked

Struct SliceMutUnchecked 

Source
pub struct SliceMutUnchecked<'a, T> { /* private fields */ }
Expand description

Implementation of Reader and Writer over a slice that does not perform any bounds checks.

This implementation inherits the lifetime of the underlying slice, and can be used for zero-copy Reader implementations.

Implementations§

Source§

impl<'a, T> SliceMutUnchecked<'a, T>

Source

pub const unsafe fn new(buf: &'a mut [T]) -> Self

Create a new SliceMutUnchecked from the given slice.

§Safety

SliceMutUnchecked’s implementation of Reader and Writer will not perform any bounds checks on the slice. It is up to the caller to ensure that any Reader or Writer operations performed are within the bounds of the slice.

§Reading
  • The total number of bytes accessed/consumed must be within the bounds of the slice.
§Writing
  • All writes performed must stay within the bounds of the slice.
  • It is permitted to overwrite the same bytes multiple times.

Trait Implementations§

Source§

impl<'a> Reader<'a> for SliceMutUnchecked<'a, u8>

Source§

const BORROW_KINDS: u8

Borrow capabilities of this reader. Read more
Source§

fn copy_into_slice(&mut self, dst: &mut [u8]) -> ReadResult<()>

Attempts to copy and consume exactly dst.len() bytes. Read more
Source§

fn copy_into_uninit_slice( &mut self, dst: &mut [MaybeUninit<u8>], ) -> ReadResult<()>

Attempts to copy and consume exactly dst.len() bytes into potentially uninitialized storage. Read more
Source§

fn take_array<const N: usize>(&mut self) -> ReadResult<[u8; N]>

Return exactly N bytes as [u8; N] and advance by N. Read more
Source§

fn take_borrowed_mut(&mut self, len: usize) -> ReadResult<&'a mut [u8]>

Return a mutably borrowed slice of exactly len bytes and advance the reader by len. Read more
Source§

fn take_borrowed(&mut self, len: usize) -> ReadResult<&'a [u8]>

Return a borrowed slice of exactly len bytes and advance the reader by len. Read more
Source§

fn take_scoped(&mut self, len: usize) -> ReadResult<&[u8]>

Return a call-site scoped slice of exactly len bytes and advance by len. Read more
Source§

fn supports_borrow(&self, kind: BorrowKind) -> bool

Checks if this reader supports the given borrow kind. Read more
Source§

fn take_byte(&mut self) -> ReadResult<u8>

Return the next byte and advance by 1. Read more
Source§

unsafe fn as_trusted_for( &mut self, n_bytes: usize, ) -> ReadResult<impl Reader<'a>>

Advance the parent by n_bytes and return a Reader that can elide bounds checks within that n_bytes window. Read more
Source§

unsafe fn as_trusted_for_seq( &mut self, len: usize, size: usize, ) -> Result<impl Reader<'a>, ReadError>

Construct a trusted window for a sequence of length len and serialized element size size. Read more
Source§

fn by_ref(&mut self) -> impl Reader<'a>

Get a mutable reference to the Reader. Read more
Source§

unsafe fn copy_into_t<T>(&mut self, dst: &mut MaybeUninit<T>) -> ReadResult<()>

Attempts to copy and consume exactly size_of::<T>() bytes from the Reader into dst. Read more
Source§

unsafe fn copy_into_slice_t<T>( &mut self, dst: &mut [MaybeUninit<T>], ) -> ReadResult<()>

Attempts to copy and consume exactly dst.len() * size_of::<T>() bytes from the Reader into dst. Read more
Source§

impl Writer for SliceMutUnchecked<'_, u8>

Source§

fn write(&mut self, src: &[u8]) -> WriteResult<()>

Write exactly src.len() bytes from the given src into the writer.
Source§

fn by_ref(&mut self) -> impl Writer

Get a mutable reference to the Writer. Read more
Source§

fn finish(&mut self) -> WriteResult<()>

Finalize the writer by performing any required cleanup or flushing. Read more
Source§

unsafe fn as_trusted_for(&mut self, n_bytes: usize) -> WriteResult<impl Writer>

Advance the parent by n_bytes and return a Writer that can elide bounds checks within that n_bytes window. Read more
Source§

unsafe fn write_t<T: ?Sized>(&mut self, src: &T) -> WriteResult<()>

Write T as bytes into the source. Read more
Source§

unsafe fn write_slice_t<T>(&mut self, src: &[T]) -> WriteResult<()>

Write [T] as bytes into the source. Read more
Source§

impl Writer for SliceMutUnchecked<'_, MaybeUninit<u8>>

Source§

fn write(&mut self, src: &[u8]) -> WriteResult<()>

Write exactly src.len() bytes from the given src into the writer.
Source§

fn by_ref(&mut self) -> impl Writer

Get a mutable reference to the Writer. Read more
Source§

fn finish(&mut self) -> WriteResult<()>

Finalize the writer by performing any required cleanup or flushing. Read more
Source§

unsafe fn as_trusted_for(&mut self, n_bytes: usize) -> WriteResult<impl Writer>

Advance the parent by n_bytes and return a Writer that can elide bounds checks within that n_bytes window. Read more
Source§

unsafe fn write_t<T: ?Sized>(&mut self, src: &T) -> WriteResult<()>

Write T as bytes into the source. Read more
Source§

unsafe fn write_slice_t<T>(&mut self, src: &[T]) -> WriteResult<()>

Write [T] as bytes into the source. Read more

Auto Trait Implementations§

§

impl<'a, T> !UnwindSafe for SliceMutUnchecked<'a, T>

§

impl<'a, T> Freeze for SliceMutUnchecked<'a, T>
where &'a mut [T]: Freeze,

§

impl<'a, T> RefUnwindSafe for SliceMutUnchecked<'a, T>
where &'a mut [T]: RefUnwindSafe,

§

impl<'a, T> Send for SliceMutUnchecked<'a, T>
where &'a mut [T]: Send,

§

impl<'a, T> Sync for SliceMutUnchecked<'a, T>
where &'a mut [T]: Sync,

§

impl<'a, T> Unpin for SliceMutUnchecked<'a, T>
where &'a mut [T]: Unpin,

§

impl<'a, T> UnsafeUnpin for SliceMutUnchecked<'a, T>
where &'a mut [T]: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.