Skip to content

Commit

Permalink
Explicitly annotate lifetime of entry methods (#1141)
Browse files Browse the repository at this point in the history
The `.key()` and `.value()` should return a borrow whose
lifetime aligns with the container, instead of the entry
itself.

Co-authored-by: LAN Xingcan <lanxingcan@lixiang.com>
  • Loading branch information
thynson and LAN Xingcan authored Oct 13, 2024
1 parent abf24e1 commit 10f0296
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crossbeam-skiplist/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,12 +1456,12 @@ impl<'a, K: 'a, V: 'a> RefEntry<'a, K, V> {
}

/// Returns a reference to the key.
pub fn key(&self) -> &K {
pub fn key(&self) -> &'a K {
&self.node.key
}

/// Returns a reference to the value.
pub fn value(&self) -> &V {
pub fn value(&self) -> &'a V {
&self.node.value
}

Expand Down
4 changes: 2 additions & 2 deletions crossbeam-skiplist/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@ impl<'a, K, V> Entry<'a, K, V> {
}

/// Returns a reference to the key.
pub fn key(&self) -> &K {
pub fn key(&self) -> &'a K {
self.inner.key()
}

/// Returns a reference to the value.
pub fn value(&self) -> &V {
pub fn value(&self) -> &'a V {
self.inner.value()
}

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-skiplist/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl<'a, T> Entry<'a, T> {
}

/// Returns a reference to the value.
pub fn value(&self) -> &T {
pub fn value(&self) -> &'a T {
self.inner.key()
}

Expand Down

0 comments on commit 10f0296

Please sign in to comment.