1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#![allow(missing_docs)] use futures::{future, Future}; use context::Context; use endpoint::{Endpoint, EndpointResult}; pub fn inspect<E, F>(endpoint: E, f: F) -> Inspect<E, F> { Inspect { endpoint, f } } #[derive(Debug)] pub struct Inspect<E, F> { endpoint: E, f: F, } impl<E, F> Endpoint for Inspect<E, F> where E: Endpoint, F: FnOnce(&E::Item), { type Item = E::Item; type Error = E::Error; type Future = future::Inspect<E::Future, F>; fn apply(self, ctx: &mut Context) -> EndpointResult<Self::Future> { let f = self.endpoint.apply(ctx)?; Ok(f.inspect(self.f)) } }