Skip to content

Commit 68fb3ac

Browse files
committed
rollup merge of #23604: apasel422/btree
`btree_map::IntoIter` (and `btree_set::IntoIter`) remains, but it is a bit trickier.
2 parents 753efb5 + 1381249 commit 68fb3ac

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/libcollections/btree/map.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub struct BTreeMap<K, V> {
7878
}
7979

8080
/// An abstract base over-which all other BTree iterators are built.
81+
#[derive(Clone)]
8182
struct AbsIter<T> {
8283
traversals: VecDeque<T>,
8384
size: usize,
@@ -1040,6 +1041,9 @@ impl<K, V, E, T> DoubleEndedIterator for AbsIter<T> where
10401041
}
10411042
}
10421043

1044+
impl<'a, K, V> Clone for Iter<'a, K, V> {
1045+
fn clone(&self) -> Iter<'a, K, V> { Iter { inner: self.inner.clone() } }
1046+
}
10431047
#[stable(feature = "rust1", since = "1.0.0")]
10441048
impl<'a, K, V> Iterator for Iter<'a, K, V> {
10451049
type Item = (&'a K, &'a V);
@@ -1082,6 +1086,9 @@ impl<K, V> DoubleEndedIterator for IntoIter<K, V> {
10821086
#[stable(feature = "rust1", since = "1.0.0")]
10831087
impl<K, V> ExactSizeIterator for IntoIter<K, V> {}
10841088

1089+
impl<'a, K, V> Clone for Keys<'a, K, V> {
1090+
fn clone(&self) -> Keys<'a, K, V> { Keys { inner: self.inner.clone() } }
1091+
}
10851092
#[stable(feature = "rust1", since = "1.0.0")]
10861093
impl<'a, K, V> Iterator for Keys<'a, K, V> {
10871094
type Item = &'a K;
@@ -1097,6 +1104,9 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
10971104
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}
10981105

10991106

1107+
impl<'a, K, V> Clone for Values<'a, K, V> {
1108+
fn clone(&self) -> Values<'a, K, V> { Values { inner: self.inner.clone() } }
1109+
}
11001110
#[stable(feature = "rust1", since = "1.0.0")]
11011111
impl<'a, K, V> Iterator for Values<'a, K, V> {
11021112
type Item = &'a V;
@@ -1111,6 +1121,9 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
11111121
#[stable(feature = "rust1", since = "1.0.0")]
11121122
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {}
11131123

1124+
impl<'a, K, V> Clone for Range<'a, K, V> {
1125+
fn clone(&self) -> Range<'a, K, V> { Range { inner: self.inner.clone() } }
1126+
}
11141127
impl<'a, K, V> Iterator for Range<'a, K, V> {
11151128
type Item = (&'a K, &'a V);
11161129

src/libcollections/btree/node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,7 @@ trait TraversalImpl {
13261326

13271327
/// A `TraversalImpl` that actually is backed by two iterators. This works in the non-moving case,
13281328
/// as no deallocation needs to be done.
1329+
#[derive(Clone)]
13291330
struct ElemsAndEdges<Elems, Edges>(Elems, Edges);
13301331

13311332
impl<K, V, E, Elems: DoubleEndedIterator, Edges: DoubleEndedIterator>
@@ -1404,6 +1405,7 @@ impl<K, V> Drop for MoveTraversalImpl<K, V> {
14041405
}
14051406

14061407
/// An abstraction over all the different kinds of traversals a node supports
1408+
#[derive(Clone)]
14071409
struct AbsTraversal<Impl> {
14081410
inner: Impl,
14091411
head_is_edge: bool,

src/libcollections/btree/set.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ impl<T: Debug> Debug for BTreeSet<T> {
628628
}
629629
}
630630

631+
impl<'a, T> Clone for Iter<'a, T> {
632+
fn clone(&self) -> Iter<'a, T> { Iter { iter: self.iter.clone() } }
633+
}
631634
#[stable(feature = "rust1", since = "1.0.0")]
632635
impl<'a, T> Iterator for Iter<'a, T> {
633636
type Item = &'a T;
@@ -658,6 +661,9 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
658661
impl<T> ExactSizeIterator for IntoIter<T> {}
659662

660663

664+
impl<'a, T> Clone for Range<'a, T> {
665+
fn clone(&self) -> Range<'a, T> { Range { iter: self.iter.clone() } }
666+
}
661667
impl<'a, T> Iterator for Range<'a, T> {
662668
type Item = &'a T;
663669

@@ -677,6 +683,11 @@ fn cmp_opt<T: Ord>(x: Option<&T>, y: Option<&T>,
677683
}
678684
}
679685

686+
impl<'a, T> Clone for Difference<'a, T> {
687+
fn clone(&self) -> Difference<'a, T> {
688+
Difference { a: self.a.clone(), b: self.b.clone() }
689+
}
690+
}
680691
#[stable(feature = "rust1", since = "1.0.0")]
681692
impl<'a, T: Ord> Iterator for Difference<'a, T> {
682693
type Item = &'a T;
@@ -692,6 +703,11 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
692703
}
693704
}
694705

706+
impl<'a, T> Clone for SymmetricDifference<'a, T> {
707+
fn clone(&self) -> SymmetricDifference<'a, T> {
708+
SymmetricDifference { a: self.a.clone(), b: self.b.clone() }
709+
}
710+
}
695711
#[stable(feature = "rust1", since = "1.0.0")]
696712
impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
697713
type Item = &'a T;
@@ -707,6 +723,11 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
707723
}
708724
}
709725

726+
impl<'a, T> Clone for Intersection<'a, T> {
727+
fn clone(&self) -> Intersection<'a, T> {
728+
Intersection { a: self.a.clone(), b: self.b.clone() }
729+
}
730+
}
710731
#[stable(feature = "rust1", since = "1.0.0")]
711732
impl<'a, T: Ord> Iterator for Intersection<'a, T> {
712733
type Item = &'a T;
@@ -728,6 +749,11 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
728749
}
729750
}
730751

752+
impl<'a, T> Clone for Union<'a, T> {
753+
fn clone(&self) -> Union<'a, T> {
754+
Union { a: self.a.clone(), b: self.b.clone() }
755+
}
756+
}
731757
#[stable(feature = "rust1", since = "1.0.0")]
732758
impl<'a, T: Ord> Iterator for Union<'a, T> {
733759
type Item = &'a T;

0 commit comments

Comments
 (0)