[][src]Trait crabsformer::Slice

pub trait Slice<Idx: ?Sized> {
    type Output: ?Sized;
    fn slice(&self, index: Idx) -> Self::Output;
}

Numeric vector slice operation

Associated Types

type Output: ?Sized

The returned type after indexing.

Loading content...

Required methods

fn slice(&self, index: Idx) -> Self::Output

Performs the slicing (container.slice[index]) operation. It returns new numeric vector with the sliced elements.

Loading content...

Implementors

impl<T> Slice<Range<usize>> for Vector<T> where
    T: Num + Copy
[src]

Implements sub-numeric vector slicing with syntax x.slice(begin .. end).

Returns a new numeric content that have elements of the given numeric vector from the range [begin..end).

This operation is O(1).

Panics

Requires that begin <= end and end <= len where len is the length of the numeric vector. Otherwise it will panic.

Examples

let x = vector![3, 1, 2, 3];
// Range
assert_eq!(x.slice(0..1), vector![3]);
// RangeTo
assert_eq!(x.slice(..2), vector![3, 1]);
// RangeFrom
assert_eq!(x.slice(2..), vector![2, 3]);
// RangeFull
assert_eq!(x.slice(..), vector![3, 1, 2, 3]);
// RangeInclusive
assert_eq!(x.slice(0..=1), vector![3, 1]);
// RangeToInclusive
assert_eq!(x.slice(..=2), vector![3, 1, 2]);

type Output = Vector<T>

impl<T> Slice<RangeFrom<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

impl<T> Slice<RangeFull> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

impl<T> Slice<RangeInclusive<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

impl<T> Slice<RangeTo<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

impl<T> Slice<RangeToInclusive<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

Loading content...