mod fixed_window;
mod sliding_window;
mod token_bucket;
#[cfg(test)]
mod proptest_policies;
pub use fixed_window::FixedWindowPolicy;
pub use sliding_window::SlidingWindowPolicy;
pub use token_bucket::TokenBucketPolicy;
use crate::codec::CodecError;
use crate::quota::Quota;
use crate::snapshot::RateLimitSnapshot;
pub trait PolicyState: Send {
fn try_acquire(&mut self, now_ms: u64) -> RateLimitSnapshot;
fn encode(&self) -> Result<Vec<u8>, CodecError>;
fn decode(bytes: &[u8], quota: Quota) -> Result<Self, CodecError>
where
Self: Sized;
fn create(quota: Quota, now_ms: u64) -> Self;
}
pub trait RateLimitPolicy: Send + Sync + 'static {
type State: PolicyState;
const STATE_ID: &'static str;
}