pub struct Dup { /* private fields */ }Expand description
A bounded, TTL-based deduplication tracker matching Gun.js dup.js.
Tracks message IDs with timestamps. Entries that haven’t been seen
within the TTL are automatically evicted. The map is also bounded by
max entries — when exceeded, the oldest third is evicted.
Implementations§
Source§impl Dup
impl Dup
Sourcepub fn new(max: usize, age_secs: u64) -> Self
pub fn new(max: usize, age_secs: u64) -> Self
Creates a new dedup tracker with the given capacity and TTL.
§Arguments
max— Maximum number of entries before forced eviction.age_secs— TTL in seconds. Entries older than this are evicted.
Sourcepub fn default_gun() -> Self
pub fn default_gun() -> Self
Creates a new dedup tracker with Gun.js defaults: 100,000 entries, 9s TTL.
Sourcepub fn check(&mut self, id: &str) -> bool
pub fn check(&mut self, id: &str) -> bool
Gun.js dup.check(id): returns true if id has been seen
within the TTL. If expired, removes it and returns false.
This is lazy eviction — expired entries are cleaned up on access.
Sourcepub fn track(&mut self, id: &str)
pub fn track(&mut self, id: &str)
Gun.js dup.track(id): marks id as seen now.
Also performs periodic cleanup if enough time has passed:
- If entries exceed
max, evicts the oldest third. - If
last_dropwas more thanage / 2ago, runsdrop().
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Dup
impl RefUnwindSafe for Dup
impl Send for Dup
impl Sync for Dup
impl Unpin for Dup
impl UnsafeUnpin for Dup
impl UnwindSafe for Dup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more