pub trait IterateByValueFrom: for<'a> IterateByValueFromGat<'a> {
// Required method
fn iter_value_from(&self, from: usize) -> IterFrom<'_, Self>;
}Expand description
A trait for obtaining a by-value iterator starting from a given position.
This is a version of IterateByValue that is useful for types in which
obtaining a global iterator and skipping is expensive.
We cannot provide a skip-based default implementation because the returned
type is not necessarily the same type as that returned by
IterateByValue::iter_value, but you are free to implement
iter_value_from that way.
§Binding the Iterator Type
To bind the iterator type or the type of its items you need to use higher-rank trait bounds, as in:
use value_traits::iter::*;
fn f<S>(s: S) where
S: IterateByValueFrom + for<'a> IterateByValueFromGat<'a, IterFrom = std::slice::Iter<'a, usize>>,
{
let _: std::slice::Iter<'_, usize> = s.iter_value_from(0);
}You can also bind the iterator using traits:
use value_traits::iter::*;
fn f<S>(s: S) where
S: IterateByValueFrom + for<'a> IterateByValueFromGat<'a, IterFrom: ExactSizeIterator>,
{
let _ = s.iter_value_from(0).len();
}In this case, you can equivalently use the IterFrom type alias, which
might be more concise:
use value_traits::iter::*;
fn f<S>(s: S) where
S: IterateByValueFrom,
for<'a> IterFrom<'a, S>: ExactSizeIterator,
{
let _ = s.iter_value_from(0).len();
}As it happens for IntoIterator, it is possible to bind the type of the
items returned by the iterator without referring to the iterator type
itself:
use value_traits::iter::*;
fn f<S>(s: S) where
S: IterateByValueFrom + for<'a> IterateByValueFromGat<'a, Item = usize>,
{
let _: Option<usize> = s.iter_value_from(0).next();
}Once again, the IterFrom type alias can be used to make the bound more
concise:
use value_traits::iter::*;
fn f<S>(s: S) where
S: IterateByValueFrom,
for<'a> IterFrom<'a, S>: Iterator<Item = usize>,
{
let _: Option<usize> = s.iter_value_from(0).next();
}Required Methods§
Sourcefn iter_value_from(&self, from: usize) -> IterFrom<'_, Self>
fn iter_value_from(&self, from: usize) -> IterFrom<'_, Self>
Returns an iterator on values starting at the given position.
Iterating from the length of the structure is allowed, and returns an exhausted iterator.
§Panics
This method will panic if from is greater than the length of the
structure being iterated, mirroring the behavior of slice indexing.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".