finchers/endpoint/wrapper/
mod.rs1mod after_apply;
4mod and_then;
5mod before_apply;
6mod map;
7mod or_reject;
8mod recover;
9mod try_chain;
10
11pub use self::after_apply::{after_apply, AfterApply};
12pub use self::and_then::{and_then, AndThen};
13pub use self::before_apply::{before_apply, BeforeApply};
14pub use self::map::{map, Map};
15pub use self::or_reject::{or_reject, or_reject_with, OrReject, OrRejectWith};
16pub use self::recover::{recover, Recover};
17
18use common::{Func, Tuple};
19use endpoint::Endpoint;
20use error::Error;
21
22use futures::IntoFuture;
23
24pub trait Wrapper<'a, E: Endpoint<'a>> {
26 type Output: Tuple;
28
29 type Endpoint: Endpoint<'a, Output = Self::Output>;
31
32 fn wrap(self, endpoint: E) -> Self::Endpoint;
34}
35
36pub trait EndpointWrapExt<'a>: Endpoint<'a> + Sized {
38 #[allow(missing_docs)]
39 fn map<F>(self, f: F) -> <Map<Self::Output, F> as Wrapper<'a, Self>>::Endpoint
40 where
41 F: Func<Self::Output> + 'a,
42 {
43 self.wrap(map(f))
44 }
45
46 #[allow(missing_docs)]
47 fn and_then<F>(self, f: F) -> <AndThen<Self::Output, F> as Wrapper<'a, Self>>::Endpoint
48 where
49 F: Func<Self::Output> + 'a,
50 F::Out: IntoFuture<Error = Error> + 'a,
51 {
52 self.wrap(and_then(f))
53 }
54}
55
56impl<'a, E: Endpoint<'a>> EndpointWrapExt<'a> for E {}