Skip to main content

UncheckedSlice

Enum UncheckedSlice 

Source
pub enum UncheckedSlice {}
Expand description

Namespace for low-level slice operations without bound checks.

All functions are unsafe and assume the caller has already validated their preconditions. Safety requirements in each method are explicit.

Implementations§

Source§

impl UncheckedSlice

Source

pub const fn range_end(len: usize, start: usize, count: usize) -> Option<usize>

Returns the exclusive end index of a checked slice range.

§Parameters
  • len: Slice length.
  • start: Start index in the slice.
  • count: Number of requested items after start.
§Returns

Some(end) if start + count <= len and no overflow occurs, or None when the requested range does not fit inside the slice.

Source

pub const fn range_fits(len: usize, start: usize, count: usize) -> bool

Returns whether a slice has at least count readable/writable items from start.

§Parameters
  • len: Slice length.
  • start: Start index in the slice.
  • count: Number of requested items after start.
§Returns

true if start + count <= len and no overflow occurs.

Source

pub fn checked_range_end( len: usize, start: usize, count: usize, message: &'static str, ) -> Result<usize>

Returns the exclusive end index of a checked slice range as an I/O result.

§Parameters
  • len: Slice length.
  • start: Start index in the slice.
  • count: Number of requested items after start.
  • message: Error message used when the requested range is invalid.
§Returns

Returns the exclusive end index when the range fits inside the slice.

§Errors

Returns ErrorKind::InvalidInput with message when start + count overflows or exceeds len.

Source

pub unsafe fn read<T: Copy>(input: &[T], index: usize) -> T

Reads one value from an unchecked slice index.

§Parameters
  • input: Source slice.
  • index: Start index that must be valid for reading one item.
§Safety

The caller must guarantee that index < input.len().

Source

pub unsafe fn write<T>(output: &mut [T], index: usize, value: T)

Writes one value to an unchecked mutable slice index.

This replaces the existing initialized element at index. The previous value is dropped before value is moved into the slot.

§Parameters
  • output: Destination slice.
  • index: Start index that must be valid for writing one item.
  • value: Value to write.
§Safety

The caller must guarantee that index < output.len().

Source

pub unsafe fn get<T>(input: &[T], index: usize) -> &T

Returns an immutable reference to one value at an unchecked slice index.

§Parameters
  • input: Source slice.
  • index: Start index that must be valid for reading one item.
§Safety

The caller must guarantee that index < input.len().

Source

pub unsafe fn get_mut<T>(output: &mut [T], index: usize) -> &mut T

Returns a mutable reference to one value at an unchecked mutable slice index.

§Parameters
  • output: Destination slice.
  • index: Start index that must be valid for writing one item.
§Safety

The caller must guarantee that index < output.len().

Source

pub unsafe fn subslice<T>(input: &[T], start: usize, count: usize) -> &[T]

Returns an immutable subslice at an unchecked offset and length.

§Parameters
  • input: Source slice.
  • start: Start index in input.
  • count: Number of items in the returned subslice.
§Safety

The caller must guarantee that start + count <= input.len() and that the addition does not overflow.

Source

pub unsafe fn subslice_mut<T>( output: &mut [T], start: usize, count: usize, ) -> &mut [T]

Returns a mutable subslice at an unchecked offset and length.

§Parameters
  • output: Destination slice.
  • start: Start index in output.
  • count: Number of items in the returned subslice.
§Safety

The caller must guarantee that start + count <= output.len() and that the addition does not overflow.

Source

pub unsafe fn copy_nonoverlapping<T: Copy>( source: &[T], source_index: usize, destination: &mut [T], destination_index: usize, count: usize, )

Copies count values between unchecked slice offsets.

§Parameters
  • source: Source slice.
  • source_index: Source offset, must be valid for count items.
  • destination: Destination slice.
  • destination_index: Destination offset, must be valid for count items.
  • count: Number of items to copy.
§Safety

The caller must guarantee that both source and destination ranges are valid for count elements, the copy does not overflow pointer arithmetic, and the two memory regions do not overlap.

Source

pub unsafe fn copy_within<T: Copy>( buffer: &mut [T], source_index: usize, destination_index: usize, count: usize, )

Copies count values between unchecked offsets in one buffer.

Overlapping source and destination ranges are supported.

§Parameters
  • buffer: Buffer containing both ranges.
  • source_index: Source offset, must be valid for count items.
  • destination_index: Destination offset, must be valid for count items.
  • count: Number of values to copy.
§Safety

The caller must guarantee that both ranges lie within buffer and that source_index + count and destination_index + count do not overflow usize.

Source

pub unsafe fn read_ne_unaligned<T: Copy>(input: &[u8], index: usize) -> T

Reads one value from an unchecked unaligned byte slice offset.

§Parameters
  • input: Source byte buffer.
  • index: Byte offset in input.
§Safety

The caller must guarantee that index..index + size_of::<T>() is a valid readable range inside input and that the addition does not overflow. Every byte in that range must be initialized and together form a valid value of T, including all bit-validity and pointer provenance requirements imposed by T.

T: Copy does not guarantee that an arbitrary byte sequence is a valid T. Primitive integer and floating-point types satisfy this representation requirement; types with restricted bit patterns, references, or pointers require additional justification from the caller.

Source

pub unsafe fn write_ne_unaligned<T: Copy>( output: &mut [u8], index: usize, value: T, )

Writes one value to an unchecked unaligned byte slice offset.

§Parameters
  • output: Destination byte buffer.
  • index: Byte offset in output.
  • value: Value to write.
§Safety

The caller must guarantee that index..index + size_of::<T>() is a valid writable range inside output and that the addition does not overflow. The complete object representation of value, including any padding bytes, must be initialized and valid to store in and later observe through the destination byte slice.

T: Copy does not guarantee initialized padding or unrestricted bytewise representation. Types containing padding, references, or pointers require additional justification from the caller.

Auto Trait Implementations§

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.