async_callback_manager/
lib.rs1use futures::{Future, Stream};
2use std::any::Any;
3#[cfg(feature = "task-debug")]
4use std::fmt::Debug;
5
6mod adaptors;
7mod constraint;
8mod error;
9mod manager;
10mod panicking_receiver_stream;
11mod task;
12
13pub use adaptors::*;
14pub use constraint::*;
15pub use error::*;
16pub use manager::task_list::{TaskInformation, TaskOutcome};
17pub use manager::*;
18pub use panicking_receiver_stream::*;
19pub use task::AsyncTask;
20pub use task::dyn_task::NoOpHandler;
21
22pub(crate) const DEFAULT_STREAM_CHANNEL_SIZE: usize = 20;
25
26pub trait BackendTask<Bkend>: Send + Any + OptPartialEq + OptDebug {
30 type Output: Send;
31 type MetadataType: PartialEq;
32 fn into_future(self, backend: &Bkend) -> impl Future<Output = Self::Output> + Send + 'static;
33 fn metadata() -> Vec<Self::MetadataType> {
36 vec![]
37 }
38}
39
40pub trait BackendStreamingTask<Bkend>: Send + Any + OptPartialEq + OptDebug {
44 type Output: Send;
45 type MetadataType: PartialEq;
46 fn into_stream(
47 self,
48 backend: &Bkend,
49 ) -> impl Stream<Item = Self::Output> + Send + Unpin + 'static;
50 fn metadata() -> Vec<Self::MetadataType> {
53 vec![]
54 }
55}
56
57pub trait TaskHandler<Input, Frntend, Bkend, Md>: OptPartialEq + OptDebug {
59 fn handle(self, input: Input) -> impl FrontendEffect<Frntend, Bkend, Md>;
60}
61
62pub trait FrontendEffect<Frntend, Bkend, Md> {
65 fn apply(self, target: &mut Frntend) -> impl Into<AsyncTask<Frntend, Bkend, Md>>;
66}
67
68#[cfg(not(feature = "task-equality"))]
73pub trait OptPartialEq {}
74#[cfg(feature = "task-equality")]
75pub trait OptPartialEq: PartialEq {}
76#[cfg(not(feature = "task-debug"))]
77pub trait OptDebug {}
78#[cfg(feature = "task-debug")]
79pub trait OptDebug: Debug {}
80#[cfg(feature = "task-debug")]
81impl<T: Debug> OptDebug for T {}
82#[cfg(not(feature = "task-debug"))]
83impl<T> OptDebug for T {}
84#[cfg(feature = "task-equality")]
85impl<T: PartialEq> OptPartialEq for T {}
86#[cfg(not(feature = "task-equality"))]
87impl<T> OptPartialEq for T {}