7 unstable releases
| 0.4.1 | Mar 17, 2025 |
|---|---|
| 0.4.0 | Jul 11, 2024 |
| 0.3.0 | Mar 7, 2023 |
| 0.2.0 | Feb 6, 2023 |
| 0.1.0 | Jan 31, 2022 |
#219 in Data structures
244,706 downloads per month
Used in 14 crates
(2 directly)
21KB
334 lines
delay_map
Overview
This crate contains two data structures, HashSetDelay and HashMapDelay. These
behave like the standard library HashSet and HashMaps with the added feature that entries
inserted into the mappings expire after a fixed period of time.
Usage
Creating a map
use delay_map::HashMapDelay;
use futures::prelude::*;
// Set a default timeout for entries
let mut delay_map = HashMapDelay::new(std::time::Duration::from_secs(1));
tokio_test::block_on(async {
delay_map.insert(1, "entry_1");
delay_map.insert(2, "entry_2");
if let Some(Ok((key, value))) = delay_map.next().await {
println!("Entry 1: {}, {}", key, value);
}
if let Some(Ok((key, value))) = delay_map.next().await {
println!("Entry 2: {}, {}", key,value);
}
});
Dependencies
~2.6–4MB
~56K SLoC