Skip to content

Commit 0d801a6

Browse files
committed
Document all entry methods
1 parent 29a4f19 commit 0d801a6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/map/core.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ pub enum Entry<'a, K, V> {
445445
}
446446

447447
impl<'a, K, V> Entry<'a, K, V> {
448+
/// Inserts the given default value in the entry if it is vacant and returns a mutable
449+
/// reference to it. Otherwise a mutable reference to an already existent value is returned.
450+
///
448451
/// Computes in **O(1)** time (amortized average).
449452
pub fn or_insert(self, default: V) -> &'a mut V {
450453
match self {
@@ -453,6 +456,9 @@ impl<'a, K, V> Entry<'a, K, V> {
453456
}
454457
}
455458

459+
/// Inserts the result of the `call` function in the entry if it is vacant and returns a mutable
460+
/// reference to it. Otherwise a mutable reference to an already existent value is returned.
461+
///
456462
/// Computes in **O(1)** time (amortized average).
457463
pub fn or_insert_with<F>(self, call: F) -> &'a mut V
458464
where
@@ -590,6 +596,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
590596
&self.key
591597
}
592598

599+
/// Takes ownership of the key, leaving the entry vacant.
593600
pub fn into_key(self) -> K {
594601
self.key
595602
}
@@ -599,6 +606,8 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
599606
self.map.len()
600607
}
601608

609+
/// Inserts the entry's key and the given value into the map, and returns a mutable reference
610+
/// to the value.
602611
pub fn insert(self, value: V) -> &'a mut V {
603612
let i = self.map.push(self.hash, self.key, value);
604613
&mut self.map.entries[i].value

src/map/core/raw.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
113113
&self.map.entries[self.index()].key
114114
}
115115

116+
/// Gets a reference to the entry's value in the map.
116117
pub fn get(&self) -> &V {
117118
&self.map.entries[self.index()].value
118119
}
119120

121+
/// Gets a mutable reference to the entry's value in the map.
122+
///
123+
/// If you need a reference which may outlive the destruction of the
124+
/// `Entry` value, see `into_mut`.
120125
pub fn get_mut(&mut self) -> &mut V {
121126
let index = self.index();
122127
&mut self.map.entries[index].value
@@ -136,6 +141,8 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
136141
unsafe { self.raw_bucket.read() }
137142
}
138143

144+
/// Converts into a mutable reference to the entry's value in the map,
145+
/// with a lifetime bound to the map itself.
139146
pub fn into_mut(self) -> &'a mut V {
140147
let index = self.index();
141148
&mut self.map.entries[index].value

0 commit comments

Comments
 (0)