pub struct RateLimitAspect { /* private fields */ }Expand description
Rate limiting aspect with token bucket algorithm.
Limits the rate at which functions can be called, useful for API throttling, resource protection, and preventing abuse.
§Example
ⓘ
use aspect_std::RateLimitAspect;
use aspect_macros::aspect;
use std::time::Duration;
// Allow 10 calls per second
let limiter = RateLimitAspect::new(10, Duration::from_secs(1));
#[aspect(limiter.clone())]
fn api_call(data: String) -> Result<(), String> {
// This function is rate-limited
Ok(())
}Implementations§
Source§impl RateLimitAspect
impl RateLimitAspect
Sourcepub fn per_function(self) -> Self
pub fn per_function(self) -> Self
Enable per-function rate limiting.
When enabled, each function gets its own token bucket.
Sourcepub fn available_tokens(&self) -> f64
pub fn available_tokens(&self) -> f64
Get current token count.
Trait Implementations§
Source§impl Aspect for RateLimitAspect
impl Aspect for RateLimitAspect
Source§fn around(
&self,
pjp: ProceedingJoinPoint<'_>,
) -> Result<Box<dyn Any>, AspectError>
fn around( &self, pjp: ProceedingJoinPoint<'_>, ) -> Result<Box<dyn Any>, AspectError>
Advice that wraps the entire target function execution. Read more
Source§fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
Advice executed after the target function completes successfully. Read more
Source§fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
Advice executed when the target function encounters an error. Read more
Source§impl Clone for RateLimitAspect
impl Clone for RateLimitAspect
Source§fn clone(&self) -> RateLimitAspect
fn clone(&self) -> RateLimitAspect
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RateLimitAspect
impl !RefUnwindSafe for RateLimitAspect
impl Send for RateLimitAspect
impl Sync for RateLimitAspect
impl Unpin for RateLimitAspect
impl UnsafeUnpin for RateLimitAspect
impl !UnwindSafe for RateLimitAspect
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