Skip to main content

InputToRateKey

Trait InputToRateKey 

pub trait InputToRateKey<Input>:
    Send
    + Sync
    + 'static {
    type Key: RateKey;

    // Required method
    fn rate_key(
        &self,
        input: &Input,
    ) -> Result<Option<Self::Key>, Box<dyn Error + Sync + Send>>;
}
Available on crate feature net only.
Expand description

Derives the RateKey of an input for a KeyedRatePolicy.

Ok(None) means the key cannot be derived for this input (e.g. no client IP is known); how that is handled is up to the policy (KeyedRatePolicy::with_missing_key_allowed).

Any Fn(&Input) -> Result<Option<K>, BoxError> is an extractor.

Required Associated Types§

type Key: RateKey

The key type produced by this extractor.

Required Methods§

fn rate_key( &self, input: &Input, ) -> Result<Option<Self::Key>, Box<dyn Error + Sync + Send>>

Derive the rate key from the given input.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

§

impl<Input, K, F> InputToRateKey<Input> for F
where F: Fn(&Input) -> Result<Option<K>, Box<dyn Error + Sync + Send>> + Send + Sync + 'static, K: RateKey,

§

type Key = K

§

impl<Input> InputToRateKey<Input> for ClientIpRateKey
where Input: ExtensionsRef + Send + Sync + 'static,

§

type Key = IpAddr