From 10f0296a274f5c4b904a9e6bf95b0ca7e37708cb Mon Sep 17 00:00:00 2001 From: Xingcan LAN Date: Sun, 13 Oct 2024 14:29:34 +0800 Subject: [PATCH] Explicitly annotate lifetime of entry methods (#1141) The `.key()` and `.value()` should return a borrow whose lifetime aligns with the container, instead of the entry itself. Co-authored-by: LAN Xingcan --- crossbeam-skiplist/src/base.rs | 4 ++-- crossbeam-skiplist/src/map.rs | 4 ++-- crossbeam-skiplist/src/set.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crossbeam-skiplist/src/base.rs b/crossbeam-skiplist/src/base.rs index 1dd27e20c..f3c90b1f9 100644 --- a/crossbeam-skiplist/src/base.rs +++ b/crossbeam-skiplist/src/base.rs @@ -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 } diff --git a/crossbeam-skiplist/src/map.rs b/crossbeam-skiplist/src/map.rs index b195a66f9..e131e79a9 100644 --- a/crossbeam-skiplist/src/map.rs +++ b/crossbeam-skiplist/src/map.rs @@ -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() } diff --git a/crossbeam-skiplist/src/set.rs b/crossbeam-skiplist/src/set.rs index 3093ae4aa..b185ff8ba 100644 --- a/crossbeam-skiplist/src/set.rs +++ b/crossbeam-skiplist/src/set.rs @@ -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() }