W3cubDocs

/Rust

Function slice_get_unchecked

pub const unsafe fn slice_get_unchecked<ItemPtr, SlicePtr, T>(
    slice_ptr: SlicePtr,
    index: usize,
) -> ItemPtrwhere
    ItemPtr: ChangePointee<[T], Pointee = T, Output = SlicePtr>,
πŸ”¬This is a nightly-only experimental API. (core_intrinsics)

Projects to the index-th element of slice_ptr, as the same kind of pointer as the slice was provided – so &mut [T] β†’ &mut T, &[T] β†’ &T, *mut [T] β†’ *mut T, or *const [T] β†’ *const T – without a bounds check.

This is exposed via <usize as SliceIndex>::get(_unchecked)(_mut), and isn’t intended to be used elsewhere.

Expands in MIR to {&, &mut, &raw const, &raw mut} (*slice_ptr)[index], depending on the types involved, so no backend support is needed.

Safety

  • index < PtrMetadata(slice_ptr), so the indexing is in-bounds for the slice
  • the resulting offsetting is in-bounds of the allocation, which is always the case for references, but needs to be upheld manually for pointers

Β© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/intrinsics/fn.slice_get_unchecked.html