diff --git a/src/lib.rs b/src/lib.rs index f252ccc..29548d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,7 @@ impl ExpiringMap { } /// 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> { + pub fn insert(&mut self, key: K, value: V, ttl: Duration) -> Option { self.vacuum_if_needed(); let entry = ExpiryValue { inserted: Instant::now(), @@ -185,6 +185,7 @@ impl ExpiringMap { self.inner .insert(key, entry) .filter(ExpiryValue::not_expired) + .map(ExpiryValue::value) } /// If this key exists and is not expired, returns true diff --git a/src/test.rs b/src/test.rs index c3f268d..7144e2d 100644 --- a/src/test.rs +++ b/src/test.rs @@ -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]