#![deny(
clippy::disallowed_methods,
clippy::suspicious,
clippy::style,
clippy::clone_on_ref_ptr,
missing_debug_implementations,
missing_copy_implementations
)]
#![warn(clippy::pedantic, missing_docs)]
#![allow(clippy::module_name_repetitions)]
use std::future::Future;
pub mod executor;
pub mod graph;
mod nonblock;
pub mod prelude {
pub use super::{
graph::{ExecutorBuilderExt, SchedulerCore},
ExecutorBuilderAsync, ExecutorBuilderCore, ExecutorBuilderSync, ExecutorCore,
ExecutorHandle,
};
}
pub trait AsyncHandler<J, H> {
type Output;
fn handle(&self, job: J, handle: H) -> impl Future<Output = Self::Output> + Send;
}
impl<J, H, T: Future + Send, F: Fn(J, H) -> T> AsyncHandler<J, H> for F {
type Output = T::Output;
fn handle(&self, job: J, handle: H) -> impl Future<Output = Self::Output> + Send {
self(job, handle)
}
}
pub trait ExecutorBuilderCore<J> {
type Error: std::error::Error;
type Executor: ExecutorCore<J>;
}
pub trait ExecutorBuilder<J, F>: ExecutorBuilderCore<J> {
fn build(self, work: F) -> Result<Self::Executor, Self::Error>;
}
pub trait ExecutorBuilderSync<J>: ExecutorBuilderCore<J> {
fn build<F: Fn(J, <Self::Executor as ExecutorCore<J>>::Handle<'_>) + Clone + Send + 'static>(
self,
work: F,
) -> Result<Self::Executor, Self::Error>;
}
pub trait ExecutorBuilderAsync<J>: ExecutorBuilderCore<J> {
fn build_async<
F: for<'h> AsyncHandler<J, <Self::Executor as ExecutorCore<J>>::Handle<'h>, Output = ()>
+ Clone
+ Send
+ 'static,
>(
self,
work: F,
) -> Result<Self::Executor, Self::Error>;
}
pub trait ExecutorHandle<J> {
fn push(&self, job: J);
}
pub trait ExecutorCore<J>: ExecutorHandle<J> + Sized {
type Handle<'a>: ExecutorHandle<J> + Copy + 'a;
}