about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKevin Butler <haqkrs@gmail.com>2015-02-13 17:27:43 +0000
committerKevin Butler <haqkrs@gmail.com>2015-02-18 00:56:07 +0000
commit5705d48e280f8a0065c214edfb3dcdcecc323316 (patch)
tree3e053192301e4f37a473da2b484cea29db9fe885 /src
parent6c065fc8cb036785f61ff03e05c1563cbb2dd081 (diff)
downloadrust-5705d48e280f8a0065c214edfb3dcdcecc323316.tar.gz
rust-5705d48e280f8a0065c214edfb3dcdcecc323316.zip
Implement RandomAccessIterator for Cloned
Diffstat (limited to 'src')
-rw-r--r--src/libcore/iter.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 03c473ed967..299864e3b3d 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -1323,6 +1323,23 @@ impl<T, D, I> ExactSizeIterator for Cloned<I> where
     I: ExactSizeIterator<Item=D>,
 {}
 
+#[unstable(feature = "core", reason = "trait is experimental")]
+impl<T, D, I> RandomAccessIterator for Cloned<I> where
+    T: Clone,
+    D: Deref<Target=T>,
+    I: RandomAccessIterator<Item=D>
+{
+    #[inline]
+    fn indexable(&self) -> usize {
+        self.it.indexable()
+    }
+
+    #[inline]
+    fn idx(&mut self, index: usize) -> Option<T> {
+        self.it.idx(index).cloned()
+    }
+}
+
 /// An iterator that repeats endlessly
 #[derive(Clone)]
 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]