pub struct CooldownWindow(/* private fields */);Expand description
A cooldown window, in seconds, below which a publish age counts as “recent”.
A newtype rather than a bare u64 so a cooldown-window value and a plain
age-in-seconds value can never be transposed at a call site without a
compile error — the bug class a raw is_within_cooldown(age, cooldown)
free function invited (swapped argument order compiled silently).
§Examples
use deps_core::CooldownWindow;
let window = CooldownWindow::from_secs(200);
assert!(window.contains(100));
assert!(!window.contains(200));
assert!(window.contains(199));
assert_eq!(window.as_secs(), 200);Implementations§
Source§impl CooldownWindow
impl CooldownWindow
Sourcepub const fn from_secs(secs: u64) -> Self
pub const fn from_secs(secs: u64) -> Self
Builds a cooldown window from a duration in seconds.
0 is a valid window: every publish age is then >= 0, so
Self::contains never fires and the freshness callout is simply
never shown, rather than being an error case.
§Examples
use deps_core::CooldownWindow;
let window = CooldownWindow::from_secs(3600);
assert_eq!(window.as_secs(), 3600);Sourcepub const fn as_secs(self) -> u64
pub const fn as_secs(self) -> u64
Returns this window’s length in seconds.
§Examples
use deps_core::CooldownWindow;
assert_eq!(CooldownWindow::from_secs(42).as_secs(), 42);Sourcepub const fn contains(self, age_secs: u64) -> bool
pub const fn contains(self, age_secs: u64) -> bool
Whether a publish age (in seconds) falls within this cooldown window.
The bound is exclusive: age_secs < self.as_secs(). A version
published exactly this window’s length ago is not within
cooldown; one published a second earlier is. This is the single rule
applied uniformly across hover, diagnostics, and completion — no
ecosystem overrides it.
§Examples
use deps_core::CooldownWindow;
let window = CooldownWindow::from_secs(200);
assert!(window.contains(100));
assert!(!window.contains(200));
assert!(window.contains(199));Trait Implementations§
Source§impl Clone for CooldownWindow
impl Clone for CooldownWindow
impl Copy for CooldownWindow
Source§impl Debug for CooldownWindow
impl Debug for CooldownWindow
impl Eq for CooldownWindow
Source§impl Ord for CooldownWindow
impl Ord for CooldownWindow
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CooldownWindow
impl PartialEq for CooldownWindow
Source§impl PartialOrd for CooldownWindow
impl PartialOrd for CooldownWindow
impl StructuralPartialEq for CooldownWindow
Auto Trait Implementations§
impl Freeze for CooldownWindow
impl RefUnwindSafe for CooldownWindow
impl Send for CooldownWindow
impl Sync for CooldownWindow
impl Unpin for CooldownWindow
impl UnsafeUnpin for CooldownWindow
impl UnwindSafe for CooldownWindow
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.