1use finchers_core::endpoint::{Context, Endpoint};
2use finchers_core::{task, Error, Never};
3
4pub fn abort<F, E>(f: F) -> Abort<F>
6where
7 F: Fn(&mut Context) -> E + Send + Sync,
8 E: Into<Error> + Send,
9{
10 Abort { f }
11}
12
13#[allow(missing_docs)]
14#[derive(Copy, Clone, Debug)]
15pub struct Abort<F> {
16 f: F,
17}
18
19impl<F, E> Endpoint for Abort<F>
20where
21 F: Fn(&mut Context) -> E + Send + Sync,
22 E: Into<Error> + Send,
23{
24 type Output = Never;
25 type Task = task::Abort<E>;
26
27 fn apply(&self, cx: &mut Context) -> Option<Self::Task> {
28 Some(task::abort((self.f)(cx)))
29 }
30}