Skip to content

Commit 5deed73

Browse files
committed
Use Rc<str> instead of Rc<String> in HashMap docs
1 parent 637ac17 commit 5deed73

File tree

1 file changed

+7
-7
lines changed
  • src/libstd/collections/hash

1 file changed

+7
-7
lines changed

src/libstd/collections/hash/map.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2416,14 +2416,14 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
24162416
/// use std::collections::hash_map::{Entry, HashMap};
24172417
/// use std::rc::Rc;
24182418
///
2419-
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
2420-
/// map.insert(Rc::new("Stringthing".to_string()), 15);
2419+
/// let mut map: HashMap<Rc<str>, u32> = HashMap::new();
2420+
/// map.insert("Stringthing".into(), 15);
24212421
///
2422-
/// let my_key = Rc::new("Stringthing".to_string());
2422+
/// let my_key: Rc<str> = "Stringthing".into();
24232423
///
24242424
/// if let Entry::Occupied(entry) = map.entry(my_key) {
24252425
/// // Also replace the key with a handle to our other key.
2426-
/// let (old_key, old_value): (Rc<String>, u32) = entry.replace_entry(16);
2426+
/// let (old_key, old_value): (Rc<str>, u32) = entry.replace_entry(16);
24272427
/// }
24282428
///
24292429
/// ```
@@ -2446,14 +2446,14 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
24462446
/// use std::collections::hash_map::{Entry, HashMap};
24472447
/// use std::rc::Rc;
24482448
///
2449-
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
2450-
/// let mut known_strings: Vec<Rc<String>> = Vec::new();
2449+
/// let mut map: HashMap<Rc<str>, u32> = HashMap::new();
2450+
/// let mut known_strings: Vec<Rc<str>> = Vec::new();
24512451
///
24522452
/// // Initialise known strings, run program, etc.
24532453
///
24542454
/// reclaim_memory(&mut map, &known_strings);
24552455
///
2456-
/// fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) {
2456+
/// fn reclaim_memory(map: &mut HashMap<Rc<str>, u32>, known_strings: &[Rc<str>] ) {
24572457
/// for s in known_strings {
24582458
/// if let Entry::Occupied(entry) = map.entry(s.clone()) {
24592459
/// // Replaces the entry's key with our version of it in `known_strings`.

0 commit comments

Comments
 (0)