Trait PolicyExt
pub trait PolicyExt
An extension trait for Policy that provides additional adapters.
Required Methods
fn and<P, B, E>(self, other: P) -> And<Self, P> where Self: Policy<B, E> + Sized, P: Policy<B, E>,Create a new
Policythat returnsAction::Followonly ifselfandotherreturnAction::Follow.[
clone_body][Policy::clone_body] method of the returnedPolicytries to clone the body with both policies.Example
use bytes::Bytes; use http_body_util::Full; use tower_http::follow_redirect::policy::{self, clone_body_fn, Limited, PolicyExt}; enum MyBody { Bytes(Bytes), Full(Full<Bytes>), } let policy = Limited::default().and::<_, _, ()>(clone_body_fn(|body| { if let MyBody::Bytes(buf) = body { Some(MyBody::Bytes(buf.clone())) } else { None } }));fn or<P, B, E>(self, other: P) -> Or<Self, P> where Self: Policy<B, E> + Sized, P: Policy<B, E>,Create a new
Policythat returnsAction::Followif eitherselforotherreturnsAction::Follow.[
clone_body][Policy::clone_body] method of the returnedPolicytries to clone the body with both policies.Example
use tower_http::follow_redirect::policy::{self, Action, Limited, PolicyExt}; #[derive(Clone)] enum MyError { TooManyRedirects, // ... } let policy = Limited::default().or::<_, (), _>(Err(MyError::TooManyRedirects));
Implementors
impl<T> PolicyExt for Action where T: ?Sized,impl<T> PolicyExt for And<A, B> where T: ?Sized,impl<T> PolicyExt for Attempt<'a> where T: ?Sized,impl<T> PolicyExt for ClassifiedResponse<FailureClass, ClassifyEos> where T: ?Sized,impl<T> PolicyExt for CloneBodyFn<F> where T: ?Sized,impl<T> PolicyExt for FilterCredentials where T: ?Sized,impl<T> PolicyExt for FollowRedirect<S, P> where T: ?Sized,impl<T> PolicyExt for FollowRedirectLayer<P> where T: ?Sized,impl<T> PolicyExt for GrpcCode where T: ?Sized,impl<T> PolicyExt for GrpcEosErrorsAsFailures where T: ?Sized,impl<T> PolicyExt for GrpcErrorsAsFailures where T: ?Sized,impl<T> PolicyExt for GrpcFailureClass where T: ?Sized,impl<T> PolicyExt for LatencyUnit where T: ?Sized,impl<T> PolicyExt for Limited where T: ?Sized,impl<T> PolicyExt for MapFailureClass<C, F> where T: ?Sized,impl<T> PolicyExt for NeverClassifyEos<T> where T: ?Sized,impl<T> PolicyExt for Or<A, B> where T: ?Sized,impl<T> PolicyExt for RedirectFn<F> where T: ?Sized,impl<T> PolicyExt for RequestUri where T: ?Sized,impl<T> PolicyExt for ResponseFuture<S, B, P> where T: ?Sized,impl<T> PolicyExt for SameOrigin where T: ?Sized,impl<T> PolicyExt for ServerErrorsAsFailures where T: ?Sized,impl<T> PolicyExt for ServerErrorsFailureClass where T: ?Sized,impl<T> PolicyExt for SharedClassifier<C> where T: ?Sized,impl<T> PolicyExt for StatusInRangeAsFailures where T: ?Sized,impl<T> PolicyExt for StatusInRangeFailureClass where T: ?Sized,impl<T> PolicyExt for T where T: ?Sized,