]> git.lizzy.rs Git - rust.git/blobdiff - src/libcollections/btree/map.rs
Fully generalize `BTree{Map, Set}` range iterators
[rust.git] / src / libcollections / btree / map.rs
index 127f470c9aaaeb9b009f475e97d2d2911af49f41..f5d1d44b4048295b12f1bb7fd60416a17ad2245a 100644 (file)
@@ -17,7 +17,8 @@
 
 use self::Entry::*;
 
-use core::prelude::*;
+#[cfg(stage0)]
+use core::prelude::v1::*;
 
 use core::cmp::Ordering;
 use core::fmt::Debug;
@@ -530,7 +531,8 @@ enum Continuation<A, B> {
 /// to nodes. By using this module much better safety guarantees can be made, and more search
 /// boilerplate gets cut out.
 mod stack {
-    use core::prelude::*;
+    #[cfg(stage0)]
+    use core::prelude::v1::*;
     use core::marker;
     use core::mem;
     use core::ops::{Deref, DerefMut};
@@ -685,10 +687,7 @@ pub fn peek_mut(&mut self) -> &mut V {
         /// tied to the original tree.
         pub fn into_top(mut self) -> &'a mut V {
             unsafe {
-                mem::copy_mut_lifetime(
-                    self.map,
-                    self.top.from_raw_mut().val_mut()
-                )
+                &mut *(self.top.from_raw_mut().val_mut() as *mut V)
             }
         }
     }
@@ -1151,7 +1150,7 @@ fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() }
 }
 
 impl<'a, K: Ord, V> Entry<'a, K, V> {
-    #[unstable(feature = "std_misc",
+    #[unstable(feature = "entry",
                reason = "will soon be replaced by or_insert")]
     #[deprecated(since = "1.0",
                 reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
@@ -1507,7 +1506,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(collections)]
+    /// #![feature(btree_range, collections_bound)]
+    ///
     /// use std::collections::BTreeMap;
     /// use std::collections::Bound::{Included, Unbounded};
     ///
@@ -1522,7 +1522,11 @@ impl<K: Ord, V> BTreeMap<K, V> {
     /// ```
     #[unstable(feature = "btree_range",
                reason = "matches collection reform specification, waiting for dust to settle")]
-    pub fn range<'a>(&'a self, min: Bound<&K>, max: Bound<&K>) -> Range<'a, K, V> {
+    pub fn range<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&self, min: Bound<&Min>,
+                                                               max: Bound<&Max>)
+        -> Range<K, V> where
+        K: Borrow<Min> + Borrow<Max>,
+    {
         range_impl!(&self.root, min, max, as_slices_internal, iter, Range, edges, [])
     }
 
@@ -1534,14 +1538,15 @@ pub fn range<'a>(&'a self, min: Bound<&K>, max: Bound<&K>) -> Range<'a, K, V> {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(collections)]
+    /// #![feature(btree_range, collections_bound)]
+    ///
     /// use std::collections::BTreeMap;
     /// use std::collections::Bound::{Included, Excluded};
     ///
     /// let mut map: BTreeMap<&str, i32> = ["Alice", "Bob", "Carol", "Cheryl"].iter()
     ///                                                                       .map(|&s| (s, 0))
     ///                                                                       .collect();
-    /// for (_, balance) in map.range_mut(Included(&"B"), Excluded(&"Cheryl")) {
+    /// for (_, balance) in map.range_mut(Included("B"), Excluded("Cheryl")) {
     ///     *balance += 100;
     /// }
     /// for (name, balance) in &map {
@@ -1550,7 +1555,11 @@ pub fn range<'a>(&'a self, min: Bound<&K>, max: Bound<&K>) -> Range<'a, K, V> {
     /// ```
     #[unstable(feature = "btree_range",
                reason = "matches collection reform specification, waiting for dust to settle")]
-    pub fn range_mut<'a>(&'a mut self, min: Bound<&K>, max: Bound<&K>) -> RangeMut<'a, K, V> {
+    pub fn range_mut<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&mut self, min: Bound<&Min>,
+                                                                   max: Bound<&Max>)
+        -> RangeMut<K, V> where
+        K: Borrow<Min> + Borrow<Max>,
+    {
         range_impl!(&mut self.root, min, max, as_slices_internal_mut, iter_mut, RangeMut,
                                                                       edges_mut, [mut])
     }