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.
§Related traits
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§
Provided Methods§
sourcefn as_iter<'a>(&'a self) -> VectorFnIter<VectorViewFn<'a, Self, T>, &'a T> ⓘ
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.
sourcefn as_fn<'a>(&'a self) -> VectorViewFn<'a, Self, T>
fn as_fn<'a>(&'a self) -> VectorViewFn<'a, Self, T>
Converts this vector into a VectorFn that yields references &T.
sourcefn into_ring_el_fn<R: RingStore>(
self,
ring: R,
) -> CloneElFn<Self, T, CloneRingEl<R>>
fn into_ring_el_fn<R: RingStore>( self, ring: R, ) -> CloneElFn<Self, T, CloneRingEl<R>>
Converts this vector into a VectorFn that clones elements on access.
sourcefn as_ring_el_fn<'a, R: RingStore>(
&'a self,
ring: R,
) -> CloneElFn<&'a Self, T, CloneRingEl<R>>
fn as_ring_el_fn<'a, R: RingStore>( &'a self, ring: R, ) -> CloneElFn<&'a Self, T, CloneRingEl<R>>
Converts this vector into a VectorFn that clones elements on access.
sourcefn into_fn<F>(self, clone_entry: F) -> CloneElFn<Self, T, F>
fn into_fn<F>(self, clone_entry: F) -> CloneElFn<Self, T, F>
Converts this vector into a VectorFn that clones elements on access.