Rollup merge of #21951 - Gankro:entry, r=aturon
This also removes two erroneous re-exports of the Entry variants, and so is incidentally a [breaking-change], though presumably no one should have been using those. r? @aturon
This commit is contained in:
commit
d1a1d339ef
@ -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<K, V> {
|
||||
// same basic logic of `swap` and `pop`, blended together
|
||||
let mut stack = stack::PartialSearchStack::new(self);
|
||||
loop {
|
||||
|
@ -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<V> {
|
||||
///
|
||||
/// 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<V> {
|
||||
// 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()
|
||||
|
@ -929,10 +929,8 @@ fn last_two<A, B, C>((_, 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<K, V> {
|
||||
// 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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user