use futures::{Future, Stream};
use std::any::Any;
#[cfg(feature = "task-debug")]
use std::fmt::Debug;
mod adaptors;
mod constraint;
mod error;
mod manager;
mod panicking_receiver_stream;
mod task;
pub use adaptors::*;
pub use constraint::*;
pub use error::*;
pub use manager::task_list::{TaskInformation, TaskOutcome};
pub use manager::*;
pub use panicking_receiver_stream::*;
pub use task::AsyncTask;
pub use task::dyn_task::NoOpHandler;
pub(crate) const DEFAULT_STREAM_CHANNEL_SIZE: usize = 20;
pub trait BackendTask<Bkend>: Send + Any + OptPartialEq + OptDebug {
type Output: Send;
type MetadataType: PartialEq;
fn into_future(self, backend: &Bkend) -> impl Future<Output = Self::Output> + Send + 'static;
fn metadata() -> Vec<Self::MetadataType> {
vec![]
}
}
pub trait BackendStreamingTask<Bkend>: Send + Any + OptPartialEq + OptDebug {
type Output: Send;
type MetadataType: PartialEq;
fn into_stream(
self,
backend: &Bkend,
) -> impl Stream<Item = Self::Output> + Send + Unpin + 'static;
fn metadata() -> Vec<Self::MetadataType> {
vec![]
}
}
pub trait TaskHandler<Input, Frntend, Bkend, Md>: OptPartialEq + OptDebug {
fn handle(self, input: Input) -> impl FrontendEffect<Frntend, Bkend, Md>;
}
pub trait FrontendEffect<Frntend, Bkend, Md> {
fn apply(self, target: &mut Frntend) -> impl Into<AsyncTask<Frntend, Bkend, Md>>;
}
#[cfg(not(feature = "task-equality"))]
pub trait OptPartialEq {}
#[cfg(feature = "task-equality")]
pub trait OptPartialEq: PartialEq {}
#[cfg(not(feature = "task-debug"))]
pub trait OptDebug {}
#[cfg(feature = "task-debug")]
pub trait OptDebug: Debug {}
#[cfg(feature = "task-debug")]
impl<T: Debug> OptDebug for T {}
#[cfg(not(feature = "task-debug"))]
impl<T> OptDebug for T {}
#[cfg(feature = "task-equality")]
impl<T: PartialEq> OptPartialEq for T {}
#[cfg(not(feature = "task-equality"))]
impl<T> OptPartialEq for T {}