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
|
// 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/).
|
// License: [CC BY 2.5 CA](http://creativecommons.org/licenses/by/2.5/ca/).
|
||||||
|
|
||||||
pub use self::Entry::*;
|
use self::Entry::*;
|
||||||
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
|
|
||||||
@ -1137,8 +1137,7 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
|||||||
impl<'a, K: Ord, 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,
|
/// Sets the value of the entry with the VacantEntry's key,
|
||||||
/// and returns a mutable reference to it.
|
/// and returns a mutable reference to it.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn insert(self, value: V) -> &'a mut V {
|
pub fn insert(self, value: V) -> &'a mut V {
|
||||||
self.stack.insert(self.key, value)
|
self.stack.insert(self.key, value)
|
||||||
}
|
}
|
||||||
@ -1146,38 +1145,33 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
|
|||||||
|
|
||||||
impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
|
impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
|
||||||
/// Gets a reference to the value in the entry.
|
/// Gets a reference to the value in the entry.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn get(&self) -> &V {
|
pub fn get(&self) -> &V {
|
||||||
self.stack.peek()
|
self.stack.peek()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a mutable reference to the value in the entry.
|
/// Gets a mutable reference to the value in the entry.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn get_mut(&mut self) -> &mut V {
|
pub fn get_mut(&mut self) -> &mut V {
|
||||||
self.stack.peek_mut()
|
self.stack.peek_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the entry into a mutable reference to its value.
|
/// Converts the entry into a mutable reference to its value.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn into_mut(self) -> &'a mut V {
|
pub fn into_mut(self) -> &'a mut V {
|
||||||
self.stack.into_top()
|
self.stack.into_top()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the value of the entry with the OccupiedEntry's key,
|
/// Sets the value of the entry with the OccupiedEntry's key,
|
||||||
/// and returns the entry's old value.
|
/// and returns the entry's old value.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn insert(&mut self, mut value: V) -> V {
|
pub fn insert(&mut self, mut value: V) -> V {
|
||||||
mem::swap(self.stack.peek_mut(), &mut value);
|
mem::swap(self.stack.peek_mut(), &mut value);
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the value of the entry out of the map, and returns it.
|
/// Takes the value of the entry out of the map, and returns it.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn remove(self) -> V {
|
pub fn remove(self) -> V {
|
||||||
self.stack.remove()
|
self.stack.remove()
|
||||||
}
|
}
|
||||||
@ -1563,10 +1557,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(count["a"], 3u);
|
/// assert_eq!(count["a"], 3u);
|
||||||
/// ```
|
/// ```
|
||||||
/// The key must have the same ordering before or after `.to_owned()` is called.
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[unstable(feature = "collections",
|
pub fn entry(&mut self, mut key: K) -> Entry<K, V> {
|
||||||
reason = "precise API still under development")]
|
|
||||||
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
|
|
||||||
// same basic logic of `swap` and `pop`, blended together
|
// same basic logic of `swap` and `pop`, blended together
|
||||||
let mut stack = stack::PartialSearchStack::new(self);
|
let mut stack = stack::PartialSearchStack::new(self);
|
||||||
loop {
|
loop {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
pub use self::Entry::*;
|
use self::Entry::*;
|
||||||
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
|
|
||||||
@ -539,8 +539,7 @@ impl<V> VecMap<V> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(count[1], 3);
|
/// assert_eq!(count[1], 3);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "precise API still under development")]
|
|
||||||
pub fn entry(&mut self, key: usize) -> Entry<V> {
|
pub fn entry(&mut self, key: usize) -> Entry<V> {
|
||||||
// FIXME(Gankro): this is basically the dumbest implementation of
|
// FIXME(Gankro): this is basically the dumbest implementation of
|
||||||
// entry possible, because weird non-lexical borrows issues make it
|
// entry possible, because weird non-lexical borrows issues make it
|
||||||
@ -576,8 +575,7 @@ impl<'a, V> Entry<'a, V> {
|
|||||||
impl<'a, V> VacantEntry<'a, V> {
|
impl<'a, V> VacantEntry<'a, V> {
|
||||||
/// Sets the value of the entry with the VacantEntry's key,
|
/// Sets the value of the entry with the VacantEntry's key,
|
||||||
/// and returns a mutable reference to it.
|
/// and returns a mutable reference to it.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn insert(self, value: V) -> &'a mut V {
|
pub fn insert(self, value: V) -> &'a mut V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
self.map.insert(index, value);
|
self.map.insert(index, value);
|
||||||
@ -587,24 +585,21 @@ impl<'a, V> VacantEntry<'a, V> {
|
|||||||
|
|
||||||
impl<'a, V> OccupiedEntry<'a, V> {
|
impl<'a, V> OccupiedEntry<'a, V> {
|
||||||
/// Gets a reference to the value in the entry.
|
/// Gets a reference to the value in the entry.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn get(&self) -> &V {
|
pub fn get(&self) -> &V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
&self.map[index]
|
&self.map[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a mutable reference to the value in the entry.
|
/// Gets a mutable reference to the value in the entry.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn get_mut(&mut self) -> &mut V {
|
pub fn get_mut(&mut self) -> &mut V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
&mut self.map[index]
|
&mut self.map[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the entry into a mutable reference to its value.
|
/// Converts the entry into a mutable reference to its value.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn into_mut(self) -> &'a mut V {
|
pub fn into_mut(self) -> &'a mut V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
&mut self.map[index]
|
&mut self.map[index]
|
||||||
@ -612,16 +607,14 @@ impl<'a, V> OccupiedEntry<'a, V> {
|
|||||||
|
|
||||||
/// Sets the value of the entry with the OccupiedEntry's key,
|
/// Sets the value of the entry with the OccupiedEntry's key,
|
||||||
/// and returns the entry's old value.
|
/// and returns the entry's old value.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn insert(&mut self, value: V) -> V {
|
pub fn insert(&mut self, value: V) -> V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
self.map.insert(index, value).unwrap()
|
self.map.insert(index, value).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the value of the entry out of the map, and returns it.
|
/// Takes the value of the entry out of the map, and returns it.
|
||||||
#[unstable(feature = "collections",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "matches collection reform v2 specification, waiting for dust to settle")]
|
|
||||||
pub fn remove(self) -> V {
|
pub fn remove(self) -> V {
|
||||||
let index = self.index;
|
let index = self.index;
|
||||||
self.map.remove(&index).unwrap()
|
self.map.remove(&index).unwrap()
|
||||||
|
@ -929,10 +929,8 @@ impl<K, V, S, H> HashMap<K, V, S>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the given key's corresponding entry in the map for in-place manipulation.
|
/// Gets the given key's corresponding entry in the map for in-place manipulation.
|
||||||
#[unstable(feature = "std_misc",
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
reason = "precise API still being fleshed out")]
|
pub fn entry(&mut self, key: K) -> Entry<K, V> {
|
||||||
pub fn entry<'a>(&'a mut self, key: K) -> Entry<'a, K, V>
|
|
||||||
{
|
|
||||||
// Gotta resize now.
|
// Gotta resize now.
|
||||||
self.reserve(1);
|
self.reserve(1);
|
||||||
|
|
||||||
@ -1496,26 +1494,28 @@ impl<'a, K, V> Entry<'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> {
|
impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
||||||
/// Gets a reference to the value in the entry.
|
/// Gets a reference to the value in the entry.
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn get(&self) -> &V {
|
pub fn get(&self) -> &V {
|
||||||
self.elem.read().1
|
self.elem.read().1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a mutable reference to the value in the entry.
|
/// 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 {
|
pub fn get_mut(&mut self) -> &mut V {
|
||||||
self.elem.read_mut().1
|
self.elem.read_mut().1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the OccupiedEntry into a mutable reference to the value in the entry
|
/// Converts the OccupiedEntry into a mutable reference to the value in the entry
|
||||||
/// with a lifetime bound to the map itself
|
/// with a lifetime bound to the map itself
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn into_mut(self) -> &'a mut V {
|
pub fn into_mut(self) -> &'a mut V {
|
||||||
self.elem.into_mut_refs().1
|
self.elem.into_mut_refs().1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the value of the entry, and returns the entry's old value
|
/// 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 {
|
pub fn insert(&mut self, mut value: V) -> V {
|
||||||
let old_value = self.get_mut();
|
let old_value = self.get_mut();
|
||||||
mem::swap(&mut value, old_value);
|
mem::swap(&mut value, old_value);
|
||||||
@ -1523,16 +1523,16 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the value out of the entry, and returns it
|
/// Takes the value out of the entry, and returns it
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn remove(self) -> V {
|
pub fn remove(self) -> V {
|
||||||
pop_internal(self.elem).1
|
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> {
|
impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
|
||||||
/// Sets the value of the entry with the VacantEntry's key,
|
/// Sets the value of the entry with the VacantEntry's key,
|
||||||
/// and returns a mutable reference to it
|
/// and returns a mutable reference to it
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn insert(self, value: V) -> &'a mut V {
|
pub fn insert(self, value: V) -> &'a mut V {
|
||||||
match self.elem {
|
match self.elem {
|
||||||
NeqElem(bucket, ib) => {
|
NeqElem(bucket, ib) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user