Trait feanor_math::seq::VectorView

source ·
pub trait VectorView<T: ?Sized> {
    // Required methods
    fn len(&self) -> usize;
    fn at(&self, i: usize) -> &T;

    // Provided methods
    fn as_iter<'a>(&'a self) -> VectorFnIter<VectorViewFn<'a, Self, T>, &'a T>  { ... }
    fn as_fn<'a>(&'a self) -> VectorViewFn<'a, Self, T> { ... }
    fn into_ring_el_fn<R: RingStore>(
        self,
        ring: R,
    ) -> CloneElFn<Self, T, CloneRingEl<R>>
       where Self: Sized,
             T: Sized,
             R::Type: RingBase<Element = T> { ... }
    fn as_ring_el_fn<'a, R: RingStore>(
        &'a self,
        ring: R,
    ) -> CloneElFn<&'a Self, T, CloneRingEl<R>>
       where T: Sized,
             R::Type: RingBase<Element = T> { ... }
    fn into_fn<F>(self, clone_entry: F) -> CloneElFn<Self, T, F>
       where Self: Sized,
             T: Sized,
             F: Fn(&T) -> T { ... }
    fn map<F: for<'a> Fn(&'a T) -> &'a U, U>(
        self,
        func: F,
    ) -> VectorViewMap<Self, T, U, F>
       where Self: Sized { ... }
    fn step_by(self, step_by: usize) -> StepBy<Self, T>
       where Self: Sized { ... }
}
Expand description

A trait for objects that provides random-position read access to a 1-dimensional sequence (or vector) of elements.

Other traits that represent sequences are

  • ExactSizeIterator: Returns elements by value; Since elements are moved, each element is returned only once, and they must be queried in order.
  • VectorFn: Also returns elements by value, but assumes that the underlying structure produces a new element whenever a position is queried. This allows accessing positions multiple times and in a random order, but depending on the represented items, it might require cloning an element on each access.

Apart from that, there are also the subtraits VectorViewMut and SwappableVectorViewMut that allow mutating the underlying sequence (but still don’t allow moving elements out). Finally, there is SelfSubvectorView, which directly supports taking subvectors.

§Example

fn compute_sum<V: VectorView<i32>>(vec: V) -> i32 {
    let mut result = 0;
    for i in 0..vec.len() {
        result += vec.at(i);
    }
    return result;
}
assert_eq!(10, compute_sum([1, 2, 3, 4]));
assert_eq!(10, compute_sum(vec![1, 2, 3, 4]));
assert_eq!(10, compute_sum(&[1, 2, 3, 4, 5][..4]));

Required Methods§

source

fn len(&self) -> usize

source

fn at(&self, i: usize) -> &T

Provided Methods§

source

fn as_iter<'a>(&'a self) -> VectorFnIter<VectorViewFn<'a, Self, T>, &'a T>

Returns an iterator over all elements in this vector.

NB: Not called iter() to prevent name conflicts.

source

fn as_fn<'a>(&'a self) -> VectorViewFn<'a, Self, T>

Converts this vector into a VectorFn that yields references &T.

source

fn into_ring_el_fn<R: RingStore>( self, ring: R, ) -> CloneElFn<Self, T, CloneRingEl<R>>
where Self: Sized, T: Sized, R::Type: RingBase<Element = T>,

Converts this vector into a VectorFn that clones elements on access.

source

fn as_ring_el_fn<'a, R: RingStore>( &'a self, ring: R, ) -> CloneElFn<&'a Self, T, CloneRingEl<R>>
where T: Sized, R::Type: RingBase<Element = T>,

Converts this vector into a VectorFn that clones elements on access.

source

fn into_fn<F>(self, clone_entry: F) -> CloneElFn<Self, T, F>
where Self: Sized, T: Sized, F: Fn(&T) -> T,

Converts this vector into a VectorFn that clones elements on access.

source

fn map<F: for<'a> Fn(&'a T) -> &'a U, U>( self, func: F, ) -> VectorViewMap<Self, T, U, F>
where Self: Sized,

source

fn step_by(self, step_by: usize) -> StepBy<Self, T>
where Self: Sized,

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for &'a V

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

source§

impl<'a, T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for &'a mut V

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

source§

impl<T> VectorView<T> for [T]

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

source§

impl<T> VectorView<T> for Vec<T>

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

source§

impl<T, const N: usize> VectorView<T> for [T; N]

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

source§

impl<T: ?Sized, V: ?Sized + VectorView<T>> VectorView<T> for Box<V>

source§

fn len(&self) -> usize

source§

fn at(&self, i: usize) -> &T

Implementors§

source§

impl<'a, V, T> VectorView<T> for Column<'a, V, T>
where V: AsPointerToSlice<T>,

source§

impl<'a, V, T> VectorView<T> for ColumnMut<'a, V, T>
where V: AsPointerToSlice<T>,

source§

impl<C: ZnRingStore, J: IntegerRingStore, A: Allocator + Clone> VectorView<C> for ZnBase<C, J, A>

source§

impl<C: ZnRingStore, J: IntegerRingStore, A: Allocator + Clone> VectorView<C> for Zn<C, J, A>

source§

impl<R: RingStore> VectorView<<<R as RingStore>::Type as RingBase>::Element> for SparseHashMapVector<R>

source§

impl<V: VectorView<T>, T: ?Sized> VectorView<T> for StepBy<V, T>

source§

impl<V: VectorView<T>, T: ?Sized> VectorView<T> for SubvectorView<V, T>

source§

impl<V: VectorView<T>, T: ?Sized, U: ?Sized, F: for<'a> Fn(&'a T) -> &'a U> VectorView<U> for VectorViewMap<V, T, U, F>

source§

impl<V: VectorViewMut<T>, T: ?Sized, U: ?Sized, F_const: for<'a> Fn(&'a T) -> &'a U, F_mut: for<'a> FnMut(&'a mut T) -> &'a mut U> VectorView<U> for VectorViewMapMut<V, T, U, F_const, F_mut>