rok::core::collections::slice
rok::core::collections::slice: Slice<T>, a zero-copy view (stdlib
2.9.7); element i is buf[start + i * stride], and the view keeps
its buffer alive.
xs[a:b] is xs.slice(a..b) (2.3.4) and xs[a:b:k] is
xs.slice(index::slice_range(a, b, k, len)).step(k), with Python's
semantics (bounds clamp, xs[::-1] reverses). A view of a List sees
later element writes but not a regrowth, which moves the list to a new
buffer; a view of an array or StrBuf views a copy.
Structs
Slice
pub struct Slice<T>pub const fn len(self) -> usizepub const fn is_empty(self) -> boolpub const fn get(self, i: usize) -> T | noneElement
i, ornoneout of bounds.pub const fn first(self) -> T | nonepub const fn last(self) -> T | nonepub const fn step(self, k: isize) -> Slice<T>Every
kth element (k!= 0), back to front whenk< 0.pub const fn iter(self) -> SliceIter<T>pub const unsafe fn raw_parts(self) -> (GcBuf<T>, usize, usize)(buffer, start, len)of the viewed elements as one contiguous run, for runtime calls on a buffer region. A strided view is copied first, so writes through its run do not reach the view.pub const unsafe fn from_raw_parts(buf: GcBuf<T>, start: usize, len: usize) -> Slice<T>The view
raw_partstakes apart:lenelements ofbuffromstart.pub const fn to_list(self) -> List<T>A new list holding the viewed elements.
pub const fn find<B: AsBytes>(self, needle: B) -> usize | none
Trait implementations 8
impl<T> !Sync for Slice<T>impl<T> IntoIterator for Slice<T>impl<T> Index<usize> for Slice<T>impl<T> Sliceable<Range<usize>> for Slice<T>impl AsBytes for Slice<u8>impl<T: PartialEq> PartialEq for Slice<T>impl<T: Debug> Debug for Slice<T>impl<T> Transfer for Slice<T>
SliceIter
pub struct SliceIter<T>s.iter() / for x in s, in view order.
Trait implementations 3
impl<T> Iterator for SliceIter<T>impl<T> DoubleEndedIterator for SliceIter<T>impl<T> ExactSizeIterator for SliceIter<T>
Traits
AsBytes
pub trait AsBytesBytes as a view (std 3.5.1): a str (its UTF-8), a List<u8>, a
Slice<u8> or a [u8; N]. std::io re-exports it.
fn byte_slice(self) -> Slice<u8>The bytes as a view (no copy).
Implementations
impl List
pub const fn find<B: AsBytes>(self, needle: B) -> usize | noneself[:].find(needle).
Trait implementations 2
impl<T> Sliceable<Range<usize>> for List<T>impl AsBytes for List<u8>