Skip to main content

Dup

Struct Dup 

Source
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

Source

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.
Source

pub fn default_gun() -> Self

Creates a new dedup tracker with Gun.js defaults: 100,000 entries, 9s TTL.

Source

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.

Source

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_drop was more than age / 2 ago, runs drop().
Source

pub fn drop(&mut self, force_age: Option<Duration>)

Remove entries older than age. force_age overrides self.age.

This is Gun.js dup.drop(age) — called periodically to clean expired entries from the map.

Source

pub fn len(&self) -> usize

Returns the number of entries currently tracked.

Source

pub fn is_empty(&self) -> bool

Returns true if no entries are currently tracked.

Source

pub fn max(&self) -> usize

Returns the maximum capacity.

Source

pub fn age(&self) -> Duration

Returns the TTL duration.

Source

pub fn clear(&mut self)

Removes all entries, resetting the tracker to empty.

Trait Implementations§

Source§

impl Default for Dup

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V