sigil-validator-agent · rate_limit
Source declarations, signatures and documentation for rate_limit.
Source: sigil/node/sigil-validator-agent/src/rate_limit.rs. SHA-256: 2bf7ab65e23c6c53539faec6bed0c4c9132027824cf36c4a9f2a9a63f6880983.
This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.
rate_limit::RateLimiterError
#[derive(Debug, thiserror::Error)]
pub enum RateLimiterError {
#[error("rate limit exceeded: {dispatched} in last 60s, cap {cap}")]
Exceeded { dispatched: u32, cap: u32 },
}Source line: 16.
rate_limit::Clock
Pluggable clock surface so tests can advance time deterministically.
pub trait Clock: Send + Sync {
fn now_unix_ms(&self) -> u64;
}Source line: 22.
rate_limit::SystemClock
Real wall-clock implementation.
#[derive(Debug, Clone, Copy)]
pub struct SystemClock;Source line: 28.
rate_limit::ManualClock
Test clock with manually-advanced time.
#[derive(Debug, Default)]
pub struct ManualClock {
}Source line: 42.
rate_limit::ManualClock::new
pub fn new(start_ms: u64) -> Self;Source line: 47.
rate_limit::ManualClock::advance_ms
pub fn advance_ms(&self, delta_ms: u64);Source line: 52.
rate_limit::RateLimiter
Sliding-window per-minute rate limiter.
pub struct RateLimiter<C: Clock = SystemClock> {
}Source line: 64.
rate_limit::RateLimiter<SystemClock>::new
pub fn new(cap_per_minute: u32) -> Self;Source line: 80.
rate_limit::RateLimiter<C>::with_clock
pub fn with_clock(cap_per_minute: u32, clock: C) -> Self;Source line: 86.
rate_limit::RateLimiter<C>::check_and_record
Record a dispatch and return Ok if within cap, Err if not. The dispatch is recorded only on Ok; rejected dispatches do NOT count toward the limit.
pub fn check_and_record(&self) -> Result<(), RateLimiterError>;Source line: 109.
rate_limit::RateLimiter<C>::dispatched_in_window
Number of dispatches in the last 60 seconds (approximate; reflects the queue at the most recent prune).
pub fn dispatched_in_window(&self) -> u32;Source line: 125.
rate_limit::RateLimiter<C>::cap
pub fn cap(&self) -> u32;Source line: 129.