Trait rama::layer::limit::Policy

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

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

A limit Policy is used to determine whether a request 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 request is allowed to proceed.

See PolicyOutput::Ready.

type Error: Send + Sync + 'static

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

See PolicyOutput::Abort.

Required Methods§

fn check( &self, ctx: Context<State>, request: Request, ) -> impl Future<Output = PolicyResult<State, Request, Self::Guard, Self::Error>> + Send

Check whether the request is allowed to proceed.

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<M, P, State, Request> Policy<State, Request> for (Vec<(M, P)>, P)
where M: Matcher<State, Request>, P: Policy<State, Request>, State: Send + Sync + 'static, Request: Send + 'static,

§

type Guard = <P as Policy<State, Request>>::Guard

§

type Error = <P as Policy<State, Request>>::Error

§

async fn check( &self, ctx: Context<State>, request: Request, ) -> PolicyResult<State, Request, <(Vec<(M, P)>, P) as Policy<State, Request>>::Guard, <(Vec<(M, P)>, P) as Policy<State, Request>>::Error>

§

impl<M, P, State, Request> Policy<State, Request> for Vec<(M, P)>
where M: Matcher<State, Request>, P: Policy<State, Request>, State: Send + Sync + 'static, Request: Send + 'static,

§

type Guard = Option<<P as Policy<State, Request>>::Guard>

§

type Error = <P as Policy<State, Request>>::Error

§

async fn check( &self, ctx: Context<State>, request: Request, ) -> PolicyResult<State, Request, <Vec<(M, P)> as Policy<State, Request>>::Guard, <Vec<(M, P)> as Policy<State, Request>>::Error>

§

impl<State, Request, P> Policy<State, Request> for Option<P>
where P: Policy<State, Request>, State: Send + Sync + 'static, Request: Send + 'static,

§

type Guard = Option<<P as Policy<State, Request>>::Guard>

§

type Error = <P as Policy<State, Request>>::Error

§

async fn check( &self, ctx: Context<State>, request: Request, ) -> PolicyResult<State, Request, <Option<P> as Policy<State, Request>>::Guard, <Option<P> as Policy<State, Request>>::Error>

§

impl<State, Request, P> Policy<State, Request> for Box<P>
where P: Policy<State, Request>, State: Send + Sync + 'static, Request: Send + 'static,

§

type Guard = <P as Policy<State, Request>>::Guard

§

type Error = <P as Policy<State, Request>>::Error

§

async fn check( &self, ctx: Context<State>, request: Request, ) -> PolicyResult<State, Request, <Box<P> as Policy<State, Request>>::Guard, <Box<P> as Policy<State, Request>>::Error>

§

impl<State, Request, P> Policy<State, Request> for Arc<P>
where P: Policy<State, Request>, State: Send + Sync + 'static, Request: Send + 'static,

§

type Guard = <P as Policy<State, Request>>::Guard

§

type Error = <P as Policy<State, Request>>::Error

§

async fn check( &self, ctx: Context<State>, request: Request, ) -> PolicyResult<State, Request, <Arc<P> as Policy<State, Request>>::Guard, <Arc<P> as Policy<State, Request>>::Error>

Implementors§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<State, Request> Policy<State, Request> for UnlimitedPolicy
where State: Send + Sync + 'static, Request: Send + 'static,