Skip to content

Commit a8c8025

Browse files
committed
Add aliases for python and Java collections
`append` sounds strange because Rust already has append and it does something different. The reason I added it is one of my friends knew from python that it added a single element to the end of an array. When they started learning Rust, rather than looking for pop(), they wrote something like ```rust my_vec.append(&mut vec![x]); ``` which is clearly not ideal. Hopefully this would have pointed them in the right direction.
1 parent 4f20caa commit a8c8025

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
139139
/// ```
140140
#[stable(feature = "rust1", since = "1.0.0")]
141141
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
142+
#[doc(alias = "associative array")]
143+
#[doc(alias = "dict")]
144+
#[doc(alias = "map")]
142145
pub struct BTreeMap<K, V> {
143146
root: Option<Root<K, V>>,
144147
length: usize,

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

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use super::Recover;
6262
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
6363
#[stable(feature = "rust1", since = "1.0.0")]
6464
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeSet")]
65+
#[doc(alias = "set")]
6566
pub struct BTreeSet<T> {
6667
map: BTreeMap<T, ()>,
6768
}

library/alloc/src/vec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ mod spec_extend;
373373
/// [`&`]: ../../std/primitive.reference.html
374374
#[stable(feature = "rust1", since = "1.0.0")]
375375
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")]
376+
#[doc(alias = "list")]
376377
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
377378
buf: RawVec<T, A>,
378379
len: usize,

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

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ use crate::sys;
200200
201201
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
202202
#[stable(feature = "rust1", since = "1.0.0")]
203+
#[doc(alias = "associative array")]
204+
#[doc(alias = "dict")]
205+
#[doc(alias = "map")]
203206
pub struct HashMap<K, V, S = RandomState> {
204207
base: base::HashMap<K, V, S>,
205208
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use super::map::{map_try_reserve_error, RandomState};
110110
/// [`Cell`]: crate::cell::Cell
111111
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
112112
#[stable(feature = "rust1", since = "1.0.0")]
113+
#[doc(alias = "set")]
113114
pub struct HashSet<T, S = RandomState> {
114115
base: base::HashSet<T, S>,
115116
}

0 commit comments

Comments
 (0)