std::iterator: Introduce trait ExactSizeHint
The trait `ExactSizeHint` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSizeHint` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint).
This commit is contained in:
parent
0ac3e023d8
commit
4b2cc22031
2 changed files with 38 additions and 0 deletions
|
@ -2319,6 +2319,9 @@ iterator!{impl VecIterator -> &'self T}
|
|||
double_ended_iterator!{impl VecIterator -> &'self T}
|
||||
pub type RevIterator<'self, T> = Invert<VecIterator<'self, T>>;
|
||||
|
||||
impl<'self, T> ExactSizeHint for VecIterator<'self, T> {}
|
||||
impl<'self, T> ExactSizeHint for VecMutIterator<'self, T> {}
|
||||
|
||||
impl<'self, T> Clone for VecIterator<'self, T> {
|
||||
fn clone(&self) -> VecIterator<'self, T> { *self }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue