pub struct RateLimitRule { /* private fields */ }Expand description
Configuration for a single rate limit rule.
use stateset_authz::RateLimitRule;
use std::time::Duration;
let rule = RateLimitRule::new("orders", 100, Duration::from_secs(60));
assert_eq!(rule.resource_type(), "orders");
assert_eq!(rule.max_requests(), 100);
assert_eq!(rule.window(), Duration::from_secs(60));Implementations§
Source§impl RateLimitRule
impl RateLimitRule
Sourcepub fn new(
resource_type: impl Into<String>,
max_requests: u32,
window: Duration,
) -> Self
pub fn new( resource_type: impl Into<String>, max_requests: u32, window: Duration, ) -> Self
Creates a new rate limit rule.
Sourcepub fn resource_type(&self) -> &str
pub fn resource_type(&self) -> &str
Returns the resource type this rule applies to.
Sourcepub const fn max_requests(&self) -> u32
pub const fn max_requests(&self) -> u32
Returns the maximum number of requests allowed per window.
Trait Implementations§
Source§impl Clone for RateLimitRule
impl Clone for RateLimitRule
Source§fn clone(&self) -> RateLimitRule
fn clone(&self) -> RateLimitRule
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateLimitRule
impl Debug for RateLimitRule
Source§impl<'de> Deserialize<'de> for RateLimitRule
impl<'de> Deserialize<'de> for RateLimitRule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for RateLimitRule
Source§impl PartialEq for RateLimitRule
impl PartialEq for RateLimitRule
Source§impl Serialize for RateLimitRule
impl Serialize for RateLimitRule
impl StructuralPartialEq for RateLimitRule
Auto Trait Implementations§
impl Freeze for RateLimitRule
impl RefUnwindSafe for RateLimitRule
impl Send for RateLimitRule
impl Sync for RateLimitRule
impl Unpin for RateLimitRule
impl UnsafeUnpin for RateLimitRule
impl UnwindSafe for RateLimitRule
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