Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive Clone for read-only iterators #60

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/blist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl<T> Traverse<ring_buf::IntoIter<T>> for RingBuf<T> {
}

/// A by-ref iterator for a BList
#[deriving(Clone)]
pub struct Iter<'a, T: 'a>
(AbsIter<dlist::Iter<'a, RingBuf<T>>, ring_buf::Iter<'a, T>>);
/// A by-mut-ref iterator for a BList
Expand All @@ -257,6 +258,7 @@ pub struct IntoIter<T>
(AbsIter<dlist::IntoIter<RingBuf<T>>, ring_buf::IntoIter<T>>);

/// An iterator that abstracts over all three kinds of ownership for a BList
#[deriving(Clone)]
struct AbsIter<DListIter, RingBufIter> {
list_iter: DListIter,
left_block_iter: Option<RingBufIter>,
Expand Down
1 change: 1 addition & 0 deletions src/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl<E:CLike> BitXor<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
}

/// An iterator over an EnumSet
#[deriving(Clone)]
pub struct Iter<E> {
index: uint,
bits: uint,
Expand Down
1 change: 1 addition & 0 deletions src/interval_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl<T, C: Compare<T> + Default> Default for IntervalHeap<T, C> {
}

/// `IntervalHeap` iterator.
#[deriving(Clone)]
pub struct Iter<'a, T: 'a>(slice::Iter<'a, T>);

impl<T: Ord> IntervalHeap<T> {
Expand Down
5 changes: 5 additions & 0 deletions src/tree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ impl<K, V, C> TreeMap<K, V, C> where C: Compare<K> {
}

/// Lazy forward iterator over a map
#[deriving(Clone)]
#[allow(raw_pointer_deriving)]
pub struct Iter<'a, K:'a, V:'a> {
stack: Vec<&'a TreeNode<K, V>>,
// See the comment on IterMut; this is just to allow
Expand All @@ -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>,
}
Expand Down Expand Up @@ -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>);

Expand Down
2 changes: 2 additions & 0 deletions src/tree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,13 @@ impl<T, C> TreeSet<T, C> where C: Compare<T> {
}

/// 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, ()>
}
Expand Down