pub struct Limtr { /* private fields */ }Expand description
Main entity used for the communication with the rate limiter.
There can be only one instance of Limtr in the process lifetime.
Initialize it using Limtr::init function.
Implementations§
Source§impl Limtr
impl Limtr
Sourcepub async fn init(buffer: usize) -> Result<(), Error>
pub async fn init(buffer: usize) -> Result<(), Error>
Initializes the Limtr entity.
Call this function once in the warmup phase of your application.
Returns Err variant when the initialization failed.
§Example
use limtr::Limtr;
fn main() {
if let Err(error) = warmup() {
println!("Could not complete the warmup phase: {}", error);
return;
}
// (...)
}
fn warmup() -> Result<(), Box<dyn std::error::Error>> {
Limtr::init(16)?;
}pub async fn set_limit( id: impl ToString, feature: impl Feature, seconds: u32, ) -> Result<(), Error>
pub async fn update_limit( id: impl ToString, feature: impl Feature, seconds: u32, max_calls: usize, ) -> Result<u64, Error>
pub async fn get_limit( id: impl ToString, feature: impl Feature, ) -> Result<u64, Error>
pub async fn clear_all() -> Result<(), Error>
Source§impl Limtr
impl Limtr
pub async fn set_limit_local( &self, id: impl ToString, feature: impl Feature, seconds: u32, ) -> Result<(), Error>
pub async fn update_limit_local( &self, id: impl ToString, feature: impl Feature, seconds: u32, max_calls: usize, ) -> Result<u64, Error>
pub async fn get_limit_local( &self, id: impl ToString, feature: impl Feature, ) -> Result<u64, Error>
pub async fn clear_all_local(&self) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Limtr
impl RefUnwindSafe for Limtr
impl Send for Limtr
impl Sync for Limtr
impl Unpin for Limtr
impl UnwindSafe for Limtr
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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