about summary refs log tree commit diff
path: root/src/libstd/vec.rs
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-30 19:59:49 +0200
committerblake2-ppc <blake2-ppc>2013-08-30 20:03:40 +0200
commit4b2cc22031d56a4846bc0ad4e65e19892db734c4 (patch)
treefd0936df8c0f8eddda113da78792ceb18616fdf6 /src/libstd/vec.rs
parent0ac3e023d86fa84ed38bca3d34003b494fd28acf (diff)
downloadrust-4b2cc22031d56a4846bc0ad4e65e19892db734c4.tar.gz
rust-4b2cc22031d56a4846bc0ad4e65e19892db734c4.zip
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).
Diffstat (limited to 'src/libstd/vec.rs')
-rw-r--r--src/libstd/vec.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 12aebe20161..6ddb2a72286 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -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 }
 }