pub trait Sequence<T> {
type H1Iterator: for<'a> PlugLifetime<'a>;
// Required methods
fn len(&self) -> usize;
fn contains<'a>(&'a self, x: &T) -> bool
where T: PartialEq;
fn get(&self, index: usize) -> Option<&T>;
fn iter<'a>(&'a self) -> <Self::H1Iterator as PlugLifetime<'a>>::T
where <Self::H1Iterator as PlugLifetime<'a>>::T: StreamingIterator;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn first(&self) -> Option<&T> { ... }
fn last(&self) -> Option<&T> { ... }
}
Expand description
Trait for collections that store elements in a linear sequence, allowing
for linear traversal and indexing with an usize
.
§Note
The H1Iterator
bounds are not specific enough due to language
limitations. The correct declaration for the trait and H1Iterator
is:
ⓘ
trait Sequence<'a, T>
where
T: 'a
{
type H1Iterator: for<'b> PlugLifetime<'b>
where
'a: 'b,
<H1Iterator as PlugLifetime<'b>>::T: StreamingIterator;
...
}
Because we can’t declare 'a: 'b
, implementors must only allow
T: 'static
. In other words, we can’t declare that all items outlive the
iterator for any specific lifetime (so that stuff like next()
returning a
&T
is valid if T
contains references), so we must use a shotgun and
prohibit T
from containing any non-'static
references.
Also, where clauses in associated types are not stable so we have to move
StreamingIterator
bound to the iter()
declaration.
Required Associated Types§
Sourcetype H1Iterator: for<'a> PlugLifetime<'a>
type H1Iterator: for<'a> PlugLifetime<'a>
HKT iterator with a lifetime slot.