#![no_std]
extern crate no_std_compat as std;
extern crate alloc;
use std::prelude::v1::*;
#[cfg(feature = "exec_tokio")]
mod tokio;
#[cfg(feature = "exec_tokio")]
pub use tokio::TokioExecutor;
#[cfg(feature = "exec_smol")]
mod smol;
#[cfg(feature = "exec_smol")]
pub use smol::SmolExecutor;
#[cfg(feature = "exec_async_std")]
mod async_std;
pub mod read_write;
pub mod sleep;
pub mod moment;
#[cfg(feature = "exec_async_std")]
pub use async_std::AsyncStdExecutor;
use async_trait::async_trait;
use std::sync::Arc;
use std::future::Future;
pub use chrono::*;
pub use ioslice::IoSlice;
pub type BoxError = Box<dyn core_error::Error + Send + Sync>;
#[async_trait]
pub trait Executor<X>: Send + Sync
{
async fn context() -> Result<Self, futures_task::SpawnError>
where
Self: Sized;
async fn set_context(&mut self, executor: X);
async fn enter_context(&self);
async fn get_executor(&self) -> &X;
fn context_sync() -> Result<Self, futures_task::SpawnError>
where
Self: Sized;
fn set_context_sync(&mut self, executor: X);
fn enter_context_sync(&self);
fn get_executor_sync(&self) -> &X;
}
#[async_trait]
pub trait ExecutorPerform<X>: Send + Sync
{
async fn spawn_in_context<F>(future: F) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, futures_task::SpawnError>
where
F: Future + Send + 'static,
F::Output: Send + 'static;
async fn spawn_from_executor<E, F>(executor: &E, future: F) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, futures_task::SpawnError>
where
E: Executor<X>,
F: Future + Send + 'static,
F::Output: Send + 'static;
async fn block_from_executor<E, F>(executor: &E, future: F) -> F::Output
where
E: Executor<X>,
F: Future + Send + 'static,
F::Output: Send + 'static;
fn spawn_in_context_sync<F>(future: F) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, futures_task::SpawnError>
where
F: Future + Send + 'static,
F::Output: Send + 'static;
fn spawn_from_executor_sync<E, F>(executor: &E, future: F) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, futures_task::SpawnError>
where
E: Executor<X>,
F: Future + Send + 'static,
F::Output: Send + 'static;
fn block_from_executor_sync<E, F>(executor: &E, future: F) -> F::Output
where
E: Executor<X>,
F: Future + Send + 'static,
F::Output: Send + 'static;
}
#[async_trait]
pub trait Timer: Send + Sync {
async fn once(duration_millis: u32) -> Self;
async fn interval(duration_millis: u32) -> Self;
async fn cancel(&mut self);
fn once_sync(duration_millis: u32) -> Self;
fn interval_sync(duration_millis: u32) -> Self;
fn cancel_sync(&mut self);
async fn tick(&mut self) -> u32;
}
#[async_trait]
pub trait Task<Out>: Future
where
Out: Send + 'static
{
async fn output(self) -> Out;
fn detach(self);
fn drop(self);
}