pub trait PolicyExt {
// Required methods
fn and<P, B, E>(self, other: P) -> And<Self, P>
where Self: Policy<B, E> + Sized,
P: Policy<B, E>;
fn or<P, B, E>(self, other: P) -> Or<Self, P>
where Self: Policy<B, E> + Sized,
P: Policy<B, E>;
}Expand description
An extension trait for Policy that provides additional adapters.
Required Methods§
Sourcefn and<P, B, E>(self, other: P) -> And<Self, P>
fn and<P, B, E>(self, other: P) -> And<Self, P>
Create a new Policy that returns Action::Follow only if self and other return
Action::Follow.
clone_body method of the returned Policy tries 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
}
}));Sourcefn or<P, B, E>(self, other: P) -> Or<Self, P>
fn or<P, B, E>(self, other: P) -> Or<Self, P>
Create a new Policy that returns Action::Follow if either self or other returns
Action::Follow.
clone_body method of the returned Policy tries 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));