From 900f39a8791ffb9e36820e8d75ef1b5e15497525 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Fri, 2 Jan 2015 08:21:06 -0500 Subject: [PATCH] derive `Clone` for read-only iterators --- src/blist.rs | 2 ++ src/enum_set.rs | 1 + src/interval_heap.rs | 1 + src/tree/map.rs | 5 +++++ src/tree/set.rs | 2 ++ 5 files changed, 11 insertions(+) diff --git a/src/blist.rs b/src/blist.rs index a87dfdd..e0cea8f 100644 --- a/src/blist.rs +++ b/src/blist.rs @@ -247,6 +247,7 @@ impl Traverse> for RingBuf { } /// A by-ref iterator for a BList +#[deriving(Clone)] pub struct Iter<'a, T: 'a> (AbsIter>, ring_buf::Iter<'a, T>>); /// A by-mut-ref iterator for a BList @@ -257,6 +258,7 @@ pub struct IntoIter (AbsIter>, ring_buf::IntoIter>); /// An iterator that abstracts over all three kinds of ownership for a BList +#[deriving(Clone)] struct AbsIter { list_iter: DListIter, left_block_iter: Option, diff --git a/src/enum_set.rs b/src/enum_set.rs index 9d197de..7963a7b 100644 --- a/src/enum_set.rs +++ b/src/enum_set.rs @@ -244,6 +244,7 @@ impl BitXor, EnumSet> for EnumSet { } /// An iterator over an EnumSet +#[deriving(Clone)] pub struct Iter { index: uint, bits: uint, diff --git a/src/interval_heap.rs b/src/interval_heap.rs index fd7111c..bcc16d6 100644 --- a/src/interval_heap.rs +++ b/src/interval_heap.rs @@ -145,6 +145,7 @@ impl + Default> Default for IntervalHeap { } /// `IntervalHeap` iterator. +#[deriving(Clone)] pub struct Iter<'a, T: 'a>(slice::Iter<'a, T>); impl IntervalHeap { diff --git a/src/tree/map.rs b/src/tree/map.rs index ec71ac4..641b660 100644 --- a/src/tree/map.rs +++ b/src/tree/map.rs @@ -823,6 +823,8 @@ impl TreeMap where C: Compare { } /// Lazy forward iterator over a map +#[deriving(Clone)] +#[allow(raw_pointer_deriving)] pub struct Iter<'a, K:'a, V:'a> { stack: Vec<&'a TreeNode>, // See the comment on IterMut; this is just to allow @@ -834,6 +836,7 @@ pub struct Iter<'a, K:'a, V:'a> { } /// Lazy backward iterator over a map +#[deriving(Clone)] pub struct RevIter<'a, K:'a, V:'a> { iter: Iter<'a, K, V>, } @@ -872,10 +875,12 @@ pub struct RevIterMut<'a, K:'a, V:'a> { } /// TreeMap keys iterator. +#[deriving(Clone)] pub struct Keys<'a, K: 'a, V: 'a> (iter::Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>); /// TreeMap values iterator. +#[deriving(Clone)] pub struct Values<'a, K: 'a, V: 'a> (iter::Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>); diff --git a/src/tree/set.rs b/src/tree/set.rs index 699789d..e0a4cf4 100644 --- a/src/tree/set.rs +++ b/src/tree/set.rs @@ -568,11 +568,13 @@ impl TreeSet where C: Compare { } /// A lazy forward iterator over a set. +#[deriving(Clone)] pub struct Iter<'a, T:'a> { iter: tree_map::Iter<'a, T, ()> } /// A lazy backward iterator over a set. +#[deriving(Clone)] pub struct RevIter<'a, T:'a> { iter: tree_map::RevIter<'a, T, ()> }