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
impl UncheckedSlice
Sourcepub fn checked_range_end(
len: usize,
start: usize,
count: usize,
message: &'static str,
) -> Result<usize>
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 afterstart.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.
Sourcepub unsafe fn write<T>(output: &mut [T], index: usize, value: T)
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().
Sourcepub unsafe fn copy_nonoverlapping<T: Copy>(
source: &[T],
source_index: usize,
destination: &mut [T],
destination_index: usize,
count: usize,
)
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 forcountitems.destination: Destination slice.destination_index: Destination offset, must be valid forcountitems.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.
Sourcepub unsafe fn copy_within<T: Copy>(
buffer: &mut [T],
source_index: usize,
destination_index: usize,
count: usize,
)
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 forcountitems.destination_index: Destination offset, must be valid forcountitems.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.
Sourcepub unsafe fn read_ne_unaligned<T: Copy>(input: &[u8], index: usize) -> T
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 ininput.
§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.
Sourcepub unsafe fn write_ne_unaligned<T: Copy>(
output: &mut [u8],
index: usize,
value: T,
)
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 inoutput.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.