pub struct SpentKeys {
capacity: usize,
seen: HashMap<String, OffsetDateTime>,
last_swept: OffsetDateTime,
}Expand description
Keys already spent, each until its own expiry, bounded at a capacity.
Not itself synchronised: a caller holds it behind whatever lock its own read and write paths need.
Fields§
§capacity: usize§seen: HashMap<String, OffsetDateTime>§last_swept: OffsetDateTimeImplementations§
Source§impl SpentKeys
impl SpentKeys
Sourcepub fn new(capacity: usize, swept_at: OffsetDateTime) -> Self
pub fn new(capacity: usize, swept_at: OffsetDateTime) -> Self
An empty window holding at most capacity keys, counting
sweep_if_due’s interval from swept_at.
Sourcepub fn holds(&self, key: &str) -> bool
pub fn holds(&self, key: &str) -> bool
Whether key is held.
Held, not live: an elapsed entry reads as spent until a sweep drops it, which is the safe direction – refusing a key twice costs a caller one retry, admitting one twice is the replay.
Sourcepub fn sweep_if_due(&mut self, now: OffsetDateTime, interval: Duration)
pub fn sweep_if_due(&mut self, now: OffsetDateTime, interval: Duration)
sweep, if it has been at least interval since the
last one.
Sourcepub fn spend(
&mut self,
key: String,
until: OffsetDateTime,
now: OffsetDateTime,
) -> Result<(), Spent>
pub fn spend( &mut self, key: String, until: OffsetDateTime, now: OffsetDateTime, ) -> Result<(), Spent>
Spends key until until.
A full window sweeps once at now before refusing, so a window full
of elapsed keys is not a refusal.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SpentKeys
impl RefUnwindSafe for SpentKeys
impl Send for SpentKeys
impl Sync for SpentKeys
impl Unpin for SpentKeys
impl UnsafeUnpin for SpentKeys
impl UnwindSafe for SpentKeys
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more