Skip to content

Commit

Permalink
Document that OccupiedEntry.get() and .get_mut() can panic
Browse files Browse the repository at this point in the history
  • Loading branch information
tormol committed Feb 13, 2023
1 parent cdecd15 commit 0eb5d2f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ pub enum Entry<'a, K: 'a, V: 'a> {

impl<'a, K: 'a, V: 'a> OccupiedEntry<'a, K, V> {
/// Gets a reference to the first item in value in the vector corresponding to entry.
///
/// # Panics
///
/// This method will panic if the key has zero values.
pub fn get(&self) -> &V {
&self.inner.get()[0]
self.inner.get().first().expect("no values in entry")
}

/// Gets a reference to the values (vector) corresponding to entry.
Expand All @@ -42,8 +46,15 @@ impl<'a, K: 'a, V: 'a> OccupiedEntry<'a, K, V> {
}

/// Gets a mut reference to the first item in value in the vector corresponding to entry.
///
/// # Panics
///
/// This method will panic if the key has zero values.
pub fn get_mut(&mut self) -> &mut V {
&mut self.inner.get_mut()[0]
self.inner
.get_mut()
.first_mut()
.expect("no values in entry")
}

/// Gets a mut reference to the values (vector) corresponding to entry.
Expand Down

0 comments on commit 0eb5d2f

Please sign in to comment.