Skip to content

Commit c383e01

Browse files
committed
Add take as alias for remove in collection methods
This partially alleviates the issues described in RFC 3034 [0] by adding a doc alias to `take` and `take_xxx` for `remove` and `remove_xxx`. [0]: rust-lang/rfcs#3034 r? @sfackler
1 parent 5605b5d commit c383e01

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

library/alloc/src/collections/btree/map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
824824
/// assert_eq!(map.remove(&1), None);
825825
/// ```
826826
#[doc(alias = "delete")]
827+
#[doc(alias = "take")]
827828
#[stable(feature = "rust1", since = "1.0.0")]
828829
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
829830
where
@@ -851,6 +852,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
851852
/// assert_eq!(map.remove_entry(&1), Some((1, "a")));
852853
/// assert_eq!(map.remove_entry(&1), None);
853854
/// ```
855+
#[doc(alias = "take_entry")]
854856
#[stable(feature = "btreemap_remove_entry", since = "1.45.0")]
855857
pub fn remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
856858
where

library/alloc/src/collections/btree/map/entry.rs

+2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
336336
/// // println!("{}", map["poneyland"]);
337337
/// ```
338338
#[stable(feature = "map_entry_recover_keys2", since = "1.12.0")]
339+
#[doc(alias = "take_entry")]
339340
pub fn remove_entry(self) -> (K, V) {
340341
self.remove_kv()
341342
}
@@ -457,6 +458,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
457458
/// // println!("{}", map["poneyland"]);
458459
/// ```
459460
#[stable(feature = "rust1", since = "1.0.0")]
461+
#[doc(alias = "take")]
460462
pub fn remove(self) -> V {
461463
self.remove_kv().1
462464
}

library/alloc/src/collections/linked_list.rs

+3
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ impl<T> LinkedList<T> {
909909
/// assert_eq!(d.remove(0), 3);
910910
/// assert_eq!(d.remove(0), 1);
911911
/// ```
912+
#[doc(alias = "take")]
912913
#[unstable(feature = "linked_list_remove", issue = "69210")]
913914
pub fn remove(&mut self, at: usize) -> T {
914915
let len = self.len();
@@ -1406,6 +1407,7 @@ impl<'a, T> CursorMut<'a, T> {
14061407
///
14071408
/// If the cursor is currently pointing to the "ghost" non-element then no element
14081409
/// is removed and `None` is returned.
1410+
#[doc(alias = "take_current")]
14091411
#[unstable(feature = "linked_list_cursors", issue = "58533")]
14101412
pub fn remove_current(&mut self) -> Option<T> {
14111413
let unlinked_node = self.current?;
@@ -1424,6 +1426,7 @@ impl<'a, T> CursorMut<'a, T> {
14241426
///
14251427
/// If the cursor is currently pointing to the "ghost" non-element then no element
14261428
/// is removed and `None` is returned.
1429+
#[doc(alias = "take_current_as_list")]
14271430
#[unstable(feature = "linked_list_cursors", issue = "58533")]
14281431
pub fn remove_current_as_list(&mut self) -> Option<LinkedList<T>> {
14291432
let mut unlinked_node = self.current?;

library/alloc/src/collections/vec_deque/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@ impl<T> VecDeque<T> {
17831783
/// assert_eq!(buf.remove(1), Some(2));
17841784
/// assert_eq!(buf, [1, 3]);
17851785
/// ```
1786+
#[doc(alias = "take")]
17861787
#[stable(feature = "rust1", since = "1.0.0")]
17871788
pub fn remove(&mut self, index: usize) -> Option<T> {
17881789
if self.is_empty() || self.len() <= index {

library/std/src/collections/hash/map.rs

+5
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ where
860860
/// assert_eq!(map.remove(&1), None);
861861
/// ```
862862
#[doc(alias = "delete")]
863+
#[doc(alias = "take")]
863864
#[inline]
864865
#[stable(feature = "rust1", since = "1.0.0")]
865866
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
@@ -889,6 +890,7 @@ where
889890
/// assert_eq!(map.remove(&1), None);
890891
/// # }
891892
/// ```
893+
#[doc(alias = "take_entry")]
892894
#[inline]
893895
#[stable(feature = "hash_map_remove_entry", since = "1.27.0")]
894896
pub fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
@@ -1717,13 +1719,15 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
17171719

17181720
/// Takes the value out of the entry, and returns it.
17191721
#[inline]
1722+
#[doc(alias = "take")]
17201723
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17211724
pub fn remove(self) -> V {
17221725
self.base.remove()
17231726
}
17241727

17251728
/// Take the ownership of the key and value from the map.
17261729
#[inline]
1730+
#[doc(alias = "take_entry")]
17271731
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17281732
pub fn remove_entry(self) -> (K, V) {
17291733
self.base.remove_entry()
@@ -2541,6 +2545,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
25412545
/// assert_eq!(map.contains_key("poneyland"), false);
25422546
/// ```
25432547
#[inline]
2548+
#[doc(alias = "take")]
25442549
#[stable(feature = "rust1", since = "1.0.0")]
25452550
pub fn remove(self) -> V {
25462551
self.base.remove()

0 commit comments

Comments
 (0)