Policy

Trait Policy 

pub trait Policy<Input>:
    Send
    + Sync
    + 'static {
    type Guard: Send + 'static;
    type Error: Send + 'static;

    // Required method
    fn check(
        &self,
        input: Input,
    ) -> impl Future<Output = PolicyResult<Input, Self::Guard, Self::Error>> + Send;
}
Expand description

A limit Policy is used to determine whether a input is allowed to proceed, and if not, how to handle it.

Required Associated Types§

type Guard: Send + 'static

The guard type that is returned when the input is allowed to proceed.

See PolicyOutput::Ready.

type Error: Send + 'static

The error type that is returned when the input is not allowed to proceed, and should be aborted.

See PolicyOutput::Abort.

Required Methods§

fn check( &self, input: Input, ) -> impl Future<Output = PolicyResult<Input, Self::Guard, Self::Error>> + Send

Check whether the input is allowed to proceed.

Optionally modify the input before it is passed to the inner service, which can be used to add metadata to the input regarding how the input was handled by this limit policy.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl<Input, P> Policy<Input> for &'static P
where P: Policy<Input>, Input: Send + 'static,

§

type Guard = <P as Policy<Input>>::Guard

§

type Error = <P as Policy<Input>>::Error

§

async fn check( &self, input: Input, ) -> PolicyResult<Input, <&'static P as Policy<Input>>::Guard, <&'static P as Policy<Input>>::Error>

§

impl<Input, P> Policy<Input> for Arc<P>
where P: Policy<Input>, Input: Send + 'static,

§

type Guard = <P as Policy<Input>>::Guard

§

type Error = <P as Policy<Input>>::Error

§

async fn check( &self, input: Input, ) -> PolicyResult<Input, <Arc<P> as Policy<Input>>::Guard, <Arc<P> as Policy<Input>>::Error>

§

impl<M, P, Input> Policy<Input> for (Vec<(M, P)>, P)
where M: Matcher<Input>, P: Policy<Input>, Input: Send + ExtensionsMut + 'static,

§

type Guard = <P as Policy<Input>>::Guard

§

type Error = <P as Policy<Input>>::Error

§

async fn check( &self, input: Input, ) -> PolicyResult<Input, <(Vec<(M, P)>, P) as Policy<Input>>::Guard, <(Vec<(M, P)>, P) as Policy<Input>>::Error>

Implementors§

§

impl<A, B, C, D, E, F, G, H, I, Input> Policy<Input> for Either9<A, B, C, D, E, F, G, H, I>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, E: Policy<Input>, <E as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, F: Policy<Input>, <F as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, G: Policy<Input>, <G as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, H: Policy<Input>, <H as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, I: Policy<Input>, <I as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either9<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard, <E as Policy<Input>>::Guard, <F as Policy<Input>>::Guard, <G as Policy<Input>>::Guard, <H as Policy<Input>>::Guard, <I as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, D, E, F, G, H, Input> Policy<Input> for Either8<A, B, C, D, E, F, G, H>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, E: Policy<Input>, <E as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, F: Policy<Input>, <F as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, G: Policy<Input>, <G as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, H: Policy<Input>, <H as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either8<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard, <E as Policy<Input>>::Guard, <F as Policy<Input>>::Guard, <G as Policy<Input>>::Guard, <H as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, D, E, F, G, Input> Policy<Input> for Either7<A, B, C, D, E, F, G>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, E: Policy<Input>, <E as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, F: Policy<Input>, <F as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, G: Policy<Input>, <G as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either7<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard, <E as Policy<Input>>::Guard, <F as Policy<Input>>::Guard, <G as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, D, E, F, Input> Policy<Input> for Either6<A, B, C, D, E, F>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, E: Policy<Input>, <E as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, F: Policy<Input>, <F as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either6<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard, <E as Policy<Input>>::Guard, <F as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, D, E, Input> Policy<Input> for Either5<A, B, C, D, E>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, E: Policy<Input>, <E as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either5<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard, <E as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, D, Input> Policy<Input> for Either4<A, B, C, D>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, D: Policy<Input>, <D as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either4<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard, <D as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, C, Input> Policy<Input> for Either3<A, B, C>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, C: Policy<Input>, <C as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either3<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard, <C as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<A, B, Input> Policy<Input> for Either<A, B>
where A: Policy<Input>, <A as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, B: Policy<Input>, <B as Policy<Input>>::Error: Into<Box<dyn Error + Sync + Send>>, Input: Send + 'static,

§

type Guard = Either<<A as Policy<Input>>::Guard, <B as Policy<Input>>::Guard>

§

type Error = Box<dyn Error + Sync + Send>

§

impl<B, C, Input> Policy<Input> for ConcurrentPolicy<B, C>
where B: Backoff, Input: Send + 'static, C: ConcurrentTracker,

§

impl<Input> Policy<Input> for UnlimitedPolicy
where Input: Send + 'static,

§

impl<Input, P> Policy<Input> for Option<P>
where P: Policy<Input>, Input: Send + 'static,

§

type Guard = Option<<P as Policy<Input>>::Guard>

§

type Error = <P as Policy<Input>>::Error

§

impl<Input, P> Policy<Input> for Box<P>
where P: Policy<Input>, Input: Send + 'static,

§

type Guard = <P as Policy<Input>>::Guard

§

type Error = <P as Policy<Input>>::Error

§

impl<M, P, Input> Policy<Input> for Vec<(M, P)>
where M: Matcher<Input>, P: Policy<Input>, Input: Send + ExtensionsMut + 'static,

§

type Guard = Option<<P as Policy<Input>>::Guard>

§

type Error = <P as Policy<Input>>::Error