silk/slice
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Allocation-free views of contiguous initialized elements.
When to use
Use view to borrow a subrange of an existing slice without copying its elements.
Details
Views retain the input lifetime. Bounds follow indexing: an invalid range traps. An empty range at the end is valid, including for an empty input.
Import as Slice with import silk.slice { Slice }.
Public declarations: 1.
Slice
pub struct SliceThe owner of operations that borrow ranges of existing slices.
Associated function Slice.view
pub fn view<T, 'life1>(values: &'life1 [T], offset: usize, length: usize) -> &'life1 [T]Borrows length elements starting at offset, without copying or allocating.
Details
The returned shared view cannot outlive the input. A zero-length view at the end is valid.
Gotchas
Traps if offset exceeds the input length or length exceeds the remaining range.