Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<K: PartialEq + Eq + Hash, V> ExpiringMap<K, V> {
}

/// Insert a value into the map, returning the old value if it has not expired and existed
pub fn insert(&mut self, key: K, value: V, ttl: Duration) -> Option<ExpiryValue<V>> {
pub fn insert(&mut self, key: K, value: V, ttl: Duration) -> Option<V> {
self.vacuum_if_needed();
let entry = ExpiryValue {
inserted: Instant::now(),
Expand All @@ -185,6 +185,7 @@ impl<K: PartialEq + Eq + Hash, V> ExpiringMap<K, V> {
self.inner
.insert(key, entry)
.filter(ExpiryValue::not_expired)
.map(ExpiryValue::value)
}

/// If this key exists and is not expired, returns true
Expand Down
5 changes: 1 addition & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ fn vacuum_sweeps() {
fn insert_replace() {
let mut m = ExpiringMap::new();
m.insert("v", "x", Duration::from_secs(5));
assert_eq!(
m.insert("v", "y", Duration::from_secs(5)).unwrap().value,
"x"
);
assert_eq!(m.insert("v", "y", Duration::from_secs(5)).unwrap(), "x");
}

#[test]
Expand Down