Skip to main content

KeyExtractor

Trait KeyExtractor 

Source
pub trait KeyExtractor<K, Err> {
    // Required method
    fn check_request(
        &self,
        req: &WebRequest<Err>,
        limiter: &RateLimiter<K>,
    ) -> Option<RateLimitResult>;
}
Expand description

Decides how RateLimit rate-limits a request.

Implemented for PeerIp (the default) and for any Fn(&WebRequest<Err>) -> Option<K> closure, see RateLimit::with_key.

Required Methods§

Source

fn check_request( &self, req: &WebRequest<Err>, limiter: &RateLimiter<K>, ) -> Option<RateLimitResult>

Check req against limiter; None lets the request through unchecked.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Err> KeyExtractor<IpAddr, Err> for PeerIp

Source§

impl<K, Err, F> KeyExtractor<K, Err> for F
where F: Fn(&WebRequest<Err>) -> Option<K>, K: Hash + Eq + Clone,