flowly-service 0.4.13

Flowly is a library of modular and reusable components for building robust pipelines processing audio, video and other.
Documentation
use tokio_stream::StreamExt;

use crate::Service;

#[derive(Clone)]
pub struct Except<S, F> {
    pub(crate) service: S,
    pub(crate) on_err: F,
}

impl<I, R, E, E2, F, S> Service<I> for Except<S, F>
where
    S: Service<I, Out = Result<R, E>>,
    F: Send + Sync + Fn(E) -> Option<E2>,
{
    type Out = Result<R, E2>;

    fn handle(
        &mut self,
        input: I,
        cx: &crate::Context,
    ) -> impl futures::Stream<Item = Self::Out> + Send {
        self.service.handle(input, cx).filter_map(|x| match x {
            Ok(ok) => Some(Ok(ok)),
            Err(err) => (self.on_err)(err).map(Err),
        })
    }
}