Trait flatk::GetIndex[][src]

pub trait GetIndex<'a, S> where
    S: ?Sized
{ type Output; fn get(self, set: &S) -> Option<Self::Output>; unsafe fn at_unchecked(self, set: &S) -> Self::Output
    where
        Self: Sized
, { ... } }
Expand description

A helper trait analogous to SliceIndex from the standard library.

Associated Types

Required methods

Gets the value in the set at this index.

Provided methods

Gets the value in the set at this index.

Safety

The index must be within the bounds of the set to avoid undefined behavior (UB).

The default implementation panics if the index is out of bounds instead of causing UB.

Implementations on Foreign Types

Get an element of the given UniChunked collection.

Get an element of the given UniChunked collection.

Get a [begin..end) subview of the given UniChunked collection.

Get an element of the given ChunkedN collection.

Get a [begin..end) subview of the given ChunkedN collection.

Get an element of the given Chunked collection.

Example
use flatk::*;
let v = vec![0, 1, 4, 6];
let data = (1..=6).collect::<Vec<_>>();
let s = Chunked::from_offsets(v.as_slice(), data.view());
assert_eq!(Some(&[1][..]), s.get(0));
assert_eq!(Some(&[2,3,4][..]), s.get(1));
assert_eq!(Some(&[5,6][..]), s.get(2));

Get an element of the given Chunked collection.

Example
use flatk::*;
let v = vec![0, 1, 4, 6];
let data = (1..=6).collect::<Vec<_>>();
let s = Chunked::from_offsets(v.as_slice(), data.view());
assert_eq!(Some(&[1][..]), s.get(&0));
assert_eq!(Some(&[2,3,4][..]), s.get(&1));
assert_eq!(Some(&[5,6][..]), s.get(&2));

Get a [begin..end) subview of the given Chunked collection.

Example
use flatk::*;
let data = (1..=6).collect::<Vec<_>>();
let offsets = vec![1, 2, 5, 7]; // Offsets don't have to start at 0
let s = Chunked::from_offsets(offsets.as_slice(), data.view());
let v = s.get(1..3).unwrap();
assert_eq!(Some(&[2,3,4][..]), v.get(0));
assert_eq!(Some(&[5,6][..]), v.get(1));

Implementors