}
/// HashMap iterator
+#[deriving(Clone)]
pub struct HashMapIterator<'self, K, V> {
priv iter: vec::VecIterator<'self, Option<Bucket<K, V>>>,
}
}
/// HashSet iterator
+#[deriving(Clone)]
pub struct HashSetIterator<'self, K> {
priv iter: vec::VecIterator<'self, Option<Bucket<K, ()>>>,
}
/// An iterator over the substrings of a string, separated by `sep`.
+#[deriving(Clone)]
pub struct StrCharSplitIterator<'self,Sep> {
priv string: &'self str,
priv position: uint,
/// An iterator over the start and end indicies of the matches of a
/// substring within a larger string
+#[deriving(Clone)]
pub struct StrMatchesIndexIterator<'self> {
priv haystack: &'self str,
priv needle: &'self str,
/// An iterator over the substrings of a string separated by a given
/// search string
+#[deriving(Clone)]
pub struct StrStrSplitIterator<'self> {
priv it: StrMatchesIndexIterator<'self>,
priv last_end: uint,
/// External iterator for a string's characters. Use with the `std::iterator`
/// module.
+#[deriving(Clone)]
pub struct StrCharIterator<'self> {
priv index: uint,
priv string: &'self str,
}
/// External iterator for a string's characters in reverse order. Use
/// with the `std::iterator` module.
+#[deriving(Clone)]
pub struct StrCharRevIterator<'self> {
priv index: uint,
priv string: &'self str,
/// External iterator for a string's bytes. Use with the `std::iterator`
/// module.
+#[deriving(Clone)]
pub struct StrBytesIterator<'self> {
priv it: vec::VecIterator<'self, u8>
}
/// External iterator for a string's bytes in reverse order. Use with
/// the `std::iterator` module.
+#[deriving(Clone)]
pub struct StrBytesRevIterator<'self> {
priv it: vec::VecRevIterator<'self, u8>
}
double_ended_iterator!{impl VecIterator -> &'self T}
pub type VecRevIterator<'self, T> = InvertIterator<&'self T, VecIterator<'self, T>>;
+impl<'self, T> Clone for VecIterator<'self, T> {
+ fn clone(&self) -> VecIterator<'self, T> { *self }
+}
+
//iterator!{struct VecMutIterator -> *mut T, &'self mut T}
/// An iterator for mutating the elements of a vector.
pub struct VecMutIterator<'self, T> {
pub type VecMutRevIterator<'self, T> = InvertIterator<&'self mut T, VecMutIterator<'self, T>>;
/// An iterator that moves out of a vector.
+#[deriving(Clone)]
pub struct VecConsumeIterator<T> {
priv v: ~[T],
priv idx: uint,
}
/// An iterator that moves out of a vector in reverse order.
+#[deriving(Clone)]
pub struct VecConsumeRevIterator<T> {
priv v: ~[T]
}
assert_eq!(xs.mut_rev_iter().size_hint(), (5, Some(5)));
}
+ #[test]
+ fn test_iter_clone() {
+ let xs = [1, 2, 5];
+ let mut it = xs.iter();
+ it.next();
+ let mut jt = it.clone();
+ assert_eq!(it.next(), jt.next());
+ assert_eq!(it.next(), jt.next());
+ assert_eq!(it.next(), jt.next());
+ }
+
#[test]
fn test_mut_iterator() {
use iterator::*;