Struct Limit

Source
pub struct Limit<const COUNT: usize, const PER: u64, K>(pub K::Extractor)
where
    K: Key;
Expand description

Represents a rate limit configuration with generic parameters for count and time period. This struct uses generics to allow flexible integration with any extractor that implements the Key trait.

Tuple Fields§

§0: K::Extractor

Implementations§

Source§

impl<const COUNT: usize, const PER: u64, K> Limit<COUNT, PER, K>
where K: Key,

Source

pub const fn count() -> usize

Returns the count of requests allowed within the specified period.

Source

pub const fn per() -> u64

Returns the period (in milliseconds) for which the limit applies.

Source

pub fn into_inner(self) -> K::Extractor

Consumes the limit and returns the inner extractor, allowing direct access to the underlying mechanism.

Trait Implementations§

Source§

impl<const COUNT: usize, const PER: u64, K> AsMut<<K as Key>::Extractor> for Limit<COUNT, PER, K>
where K: Key,

Source§

fn as_mut(&mut self) -> &mut K::Extractor

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const COUNT: usize, const PER: u64, K> AsRef<<K as Key>::Extractor> for Limit<COUNT, PER, K>
where K: Key,

Source§

fn as_ref(&self) -> &K::Extractor

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const COUNT: usize, const PER: u64, K> Clone for Limit<COUNT, PER, K>
where K: Key + Clone, K::Extractor: Clone,

Source§

fn clone(&self) -> Limit<COUNT, PER, K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const COUNT: usize, const PER: u64, K> Debug for Limit<COUNT, PER, K>
where K: Key + Debug, K::Extractor: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const COUNT: usize, const PER: u64, K> Default for Limit<COUNT, PER, K>
where K: Key + Default, K::Extractor: Default,

Source§

fn default() -> Limit<COUNT, PER, K>

Returns the “default value” for a type. Read more
Source§

impl<const COUNT: usize, const PER: u64, K> Deref for Limit<COUNT, PER, K>
where K: Key,

Source§

type Target = <K as Key>::Extractor

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const COUNT: usize, const PER: u64, K> DerefMut for Limit<COUNT, PER, K>
where K: Key,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<const COUNT: usize, const PER: u64, K> Display for Limit<COUNT, PER, K>
where K: Key, K::Extractor: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const C: usize, const P: u64, K, S> FromRequestParts<S> for Limit<C, P, K>
where LimitState<K>: FromRef<S>, S: Send + Sync, K: Key, K::Extractor: FromRequestParts<S>,

Source§

type Rejection = LimitRejection<<<K as Key>::Extractor as FromRequestParts<S>>::Rejection>

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request_parts<'life0, 'life1, 'async_trait>( parts: &'life0 mut Parts, state: &'life1 S, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Perform the extraction.
Source§

impl<const COUNT: usize, const PER: u64, K> Copy for Limit<COUNT, PER, K>
where K: Key + Copy, K::Extractor: Copy,

Auto Trait Implementations§

§

impl<const COUNT: usize, const PER: u64, K> Freeze for Limit<COUNT, PER, K>
where <K as Key>::Extractor: Freeze,

§

impl<const COUNT: usize, const PER: u64, K> RefUnwindSafe for Limit<COUNT, PER, K>
where <K as Key>::Extractor: RefUnwindSafe,

§

impl<const COUNT: usize, const PER: u64, K> Send for Limit<COUNT, PER, K>
where <K as Key>::Extractor: Send,

§

impl<const COUNT: usize, const PER: u64, K> Sync for Limit<COUNT, PER, K>
where <K as Key>::Extractor: Sync,

§

impl<const COUNT: usize, const PER: u64, K> Unpin for Limit<COUNT, PER, K>
where <K as Key>::Extractor: Unpin,

§

impl<const COUNT: usize, const PER: u64, K> UnwindSafe for Limit<COUNT, PER, K>
where <K as Key>::Extractor: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request<'life0, 'async_trait>( req: Request<Body>, state: &'life0 S, ) -> Pin<Box<dyn Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>> + Send + 'async_trait>>
where 'life0: 'async_trait, T: 'async_trait,

Perform the extraction.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.