From 5cbbc1282726102a796b1475490e884144bb7146 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 4 Feb 2015 19:36:02 -0500 Subject: [PATCH] stabilize core Entry API --- src/libcollections/btree/map.rs | 26 +++++++++----------------- src/libcollections/vec_map.rs | 23 ++++++++--------------- src/libstd/collections/hash/map.rs | 16 ++++++++-------- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 99ee5957913..d7f89b0cc72 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -15,7 +15,7 @@ // writing (August 2014) freely licensed under the following Creative Commons Attribution // License: [CC BY 2.5 CA](http://creativecommons.org/licenses/by/2.5/ca/). -pub use self::Entry::*; +use self::Entry::*; use core::prelude::*; @@ -1137,8 +1137,7 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> { impl<'a, K: Ord, V> VacantEntry<'a, K, V> { /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(self, value: V) -> &'a mut V { self.stack.insert(self.key, value) } @@ -1146,38 +1145,33 @@ pub fn insert(self, value: V) -> &'a mut V { impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> { /// Gets a reference to the value in the entry. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn get(&self) -> &V { self.stack.peek() } /// Gets a mutable reference to the value in the entry. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut V { self.stack.peek_mut() } /// Converts the entry into a mutable reference to its value. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn into_mut(self) -> &'a mut V { self.stack.into_top() } /// Sets the value of the entry with the OccupiedEntry's key, /// and returns the entry's old value. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, mut value: V) -> V { mem::swap(self.stack.peek_mut(), &mut value); value } /// Takes the value of the entry out of the map, and returns it. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn remove(self) -> V { self.stack.remove() } @@ -1563,10 +1557,8 @@ pub fn range_mut<'a>(&'a mut self, min: Bound<&K>, max: Bound<&K>) -> RangeMut<' /// /// assert_eq!(count["a"], 3u); /// ``` - /// The key must have the same ordering before or after `.to_owned()` is called. - #[unstable(feature = "collections", - reason = "precise API still under development")] - pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> { + #[stable(feature = "rust1", since = "1.0.0")] + pub fn entry(&mut self, mut key: K) -> Entry { // same basic logic of `swap` and `pop`, blended together let mut stack = stack::PartialSearchStack::new(self); loop { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index abcf358a192..a907d624169 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -13,7 +13,7 @@ #![allow(missing_docs)] -pub use self::Entry::*; +use self::Entry::*; use core::prelude::*; @@ -539,8 +539,7 @@ pub fn remove(&mut self, key: &uint) -> Option { /// /// assert_eq!(count[1], 3); /// ``` - #[unstable(feature = "collections", - reason = "precise API still under development")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn entry(&mut self, key: usize) -> Entry { // FIXME(Gankro): this is basically the dumbest implementation of // entry possible, because weird non-lexical borrows issues make it @@ -576,8 +575,7 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> { impl<'a, V> VacantEntry<'a, V> { /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(self, value: V) -> &'a mut V { let index = self.index; self.map.insert(index, value); @@ -587,24 +585,21 @@ pub fn insert(self, value: V) -> &'a mut V { impl<'a, V> OccupiedEntry<'a, V> { /// Gets a reference to the value in the entry. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn get(&self) -> &V { let index = self.index; &self.map[index] } /// Gets a mutable reference to the value in the entry. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut V { let index = self.index; &mut self.map[index] } /// Converts the entry into a mutable reference to its value. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn into_mut(self) -> &'a mut V { let index = self.index; &mut self.map[index] @@ -612,16 +607,14 @@ pub fn into_mut(self) -> &'a mut V { /// Sets the value of the entry with the OccupiedEntry's key, /// and returns the entry's old value. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, value: V) -> V { let index = self.index; self.map.insert(index, value).unwrap() } /// Takes the value of the entry out of the map, and returns it. - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn remove(self) -> V { let index = self.index; self.map.remove(&index).unwrap() diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 63270610472..d23d806ef59 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -929,10 +929,8 @@ fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } } /// Gets the given key's corresponding entry in the map for in-place manipulation. - #[unstable(feature = "std_misc", - reason = "precise API still being fleshed out")] - pub fn entry<'a>(&'a mut self, key: K) -> Entry<'a, K, V> - { + #[stable(feature = "rust1", since = "1.0.0")] + pub fn entry(&mut self, key: K) -> Entry { // Gotta resize now. self.reserve(1); @@ -1496,26 +1494,28 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> { } } -#[unstable(feature = "std_misc", - reason = "matches collection reform v2 specification, waiting for dust to settle")] impl<'a, K, V> OccupiedEntry<'a, K, V> { /// Gets a reference to the value in the entry. + #[stable(feature = "rust1", since = "1.0.0")] pub fn get(&self) -> &V { self.elem.read().1 } /// Gets a mutable reference to the value in the entry. + #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut V { self.elem.read_mut().1 } /// Converts the OccupiedEntry into a mutable reference to the value in the entry /// with a lifetime bound to the map itself + #[stable(feature = "rust1", since = "1.0.0")] pub fn into_mut(self) -> &'a mut V { self.elem.into_mut_refs().1 } /// Sets the value of the entry, and returns the entry's old value + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, mut value: V) -> V { let old_value = self.get_mut(); mem::swap(&mut value, old_value); @@ -1523,16 +1523,16 @@ pub fn insert(&mut self, mut value: V) -> V { } /// Takes the value out of the entry, and returns it + #[stable(feature = "rust1", since = "1.0.0")] pub fn remove(self) -> V { pop_internal(self.elem).1 } } -#[unstable(feature = "std_misc", - reason = "matches collection reform v2 specification, waiting for dust to settle")] impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it + #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(self, value: V) -> &'a mut V { match self.elem { NeqElem(bucket, ib) => {