Trait PolicyExt
pub trait PolicyExt {
// Required methods
fn and<P, B, E>(self, other: P) -> And<Self, P>
where Self: Sized + Policy<B, E>,
P: Policy<B, E>;
fn or<P, B, E>(self, other: P) -> Or<Self, P>
where Self: Sized + Policy<B, E>,
P: Policy<B, E>;
}Expand description
An extension trait for Policy that provides additional adapters.
Required Methods§
fn 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 rama_core::bytes::Bytes;
use rama_http::Body;
use rama_http::layer::follow_redirect::policy::{self, clone_body_fn, Limited, PolicyExt};
enum MyBody {
Bytes(Bytes),
Other(Body),
}
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>
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 rama_http::layer::follow_redirect::policy::{self, Action, Limited, PolicyExt};
#[derive(Clone)]
enum MyError {
TooManyRedirects,
// ...
}
let policy = Limited::default().or::<_, (), _>(Err(MyError::TooManyRedirects));