Skip to content

Commit

Permalink
Add aliases for python and Java collections
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
jyn514 committed Mar 2, 2021
1 parent 4f20caa commit a8c8025
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
#[doc(alias = "associative array")]
#[doc(alias = "dict")]
#[doc(alias = "map")]
pub struct BTreeMap<K, V> {
root: Option<Root<K, V>>,
length: usize,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use super::Recover;
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeSet")]
#[doc(alias = "set")]
pub struct BTreeSet<T> {
map: BTreeMap<T, ()>,
}
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ mod spec_extend;
/// [`&`]: ../../std/primitive.reference.html
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")]
#[doc(alias = "list")]
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
buf: RawVec<T, A>,
len: usize,
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ use crate::sys;
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "associative array")]
#[doc(alias = "dict")]
#[doc(alias = "map")]
pub struct HashMap<K, V, S = RandomState> {
base: base::HashMap<K, V, S>,
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ use super::map::{map_try_reserve_error, RandomState};
/// [`Cell`]: crate::cell::Cell
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "set")]
pub struct HashSet<T, S = RandomState> {
base: base::HashSet<T, S>,
}
Expand Down

0 comments on commit a8c8025

Please sign in to comment.