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>;
}
Available on crate feature follow-redirect only.
Expand description

An extension trait for Policy that provides additional adapters.

Required Methods§

source

fn and<P, B, E>(self, other: P) -> And<Self, P>
where Self: Policy<B, E> + Sized, P: Policy<B, E>,

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

fn or<P, B, E>(self, other: P) -> Or<Self, P>
where Self: Policy<B, E> + Sized, P: Policy<B, E>,

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§

source§

impl<T> PolicyExt for T
where T: ?Sized,