rokdocs
v0.1

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) -> usize
  • pub const fn is_empty(self) -> bool
  • pub const fn get(self, i: usize) -> T | none

    Element i, or none out of bounds.

  • pub const fn first(self) -> T | none
  • pub const fn last(self) -> T | none
  • pub const fn step(self, k: isize) -> Slice<T>

    Every kth element (k != 0), back to front when k < 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_parts takes apart: len elements of buf from start.

  • 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 AsBytes

Bytes 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 | none

    self[:].find(needle).

Trait implementations 2
  • impl<T> Sliceable<Range<usize>> for List<T>
  • impl AsBytes for List<u8>