pub trait PolicyExt {
    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>
; }
This is supported on crate feature follow-redirect only.
Expand description

An extension trait for Policy that provides additional adapters.

Required methods

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 hyper::Body;
use tower_http::follow_redirect::policy::{self, clone_body_fn, Limited, PolicyExt};

enum MyBody {
    Bytes(Bytes),
    Hyper(Body),
}

let policy = Limited::default().and::<_, _, ()>(clone_body_fn(|body| {
    if let MyBody::Bytes(buf) = body {
        Some(MyBody::Bytes(buf.clone()))
    } else {
        None
    }
}));

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));

Implementors