#![no_std]
#![warn(missing_docs)]
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::must_use_candidate)]
#![allow(async_fn_in_trait)]
extern crate alloc;
#[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;
#[cfg(feature = "exec_async_std")]
#[allow(deprecated)]
pub use async_std::AsyncStdExecutor;
#[cfg(feature = "exec_embassy")]
mod embassy;
#[cfg(feature = "exec_embassy")]
pub use embassy::EmbassyExecutor;
pub mod read_write;
pub mod sleep;
pub mod moment;
use alloc::boxed::Box;
use alloc::sync::Arc;
use core::future::Future;
use core::pin::Pin;
pub use chrono::Duration as ChronoDuration;
pub use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
#[deprecated(
since = "0.0.19",
note = "Import chrono types directly from the `chrono` crate or use the specific re-exports (DateTime, Utc, ChronoDuration, etc.) from this crate's root."
)]
pub mod chrono_compat {
pub use chrono::*;
}
pub use read_write::IoSlice;
pub type BoxError = alloc::boxed::Box<dyn core::error::Error + Send + Sync>;
#[derive(Debug)]
pub struct SpawnError {
_private: (),
}
impl SpawnError {
pub const fn new() -> Self {
Self { _private: () }
}
}
impl Default for SpawnError {
fn default() -> Self {
Self::new()
}
}
impl core::fmt::Display for SpawnError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "failed to spawn task")
}
}
impl core::error::Error for SpawnError {}
pub trait Executor<X>: Send + Sync {
fn context() -> impl Future<Output = Result<Self, SpawnError>> + Send
where
Self: Sized;
fn set_context(&mut self, executor: X) -> impl Future<Output = ()> + Send;
fn enter_context(&self) -> impl Future<Output = ()> + Send;
fn get_executor<'a>(&'a self) -> impl Future<Output = &'a X> + Send
where
X: 'a;
fn context_sync() -> Result<Self, SpawnError>
where
Self: Sized;
fn set_context_sync(&mut self, executor: X);
fn enter_context_sync(&self);
fn get_executor_sync(&self) -> &X;
}
pub trait ExecutorPerform<X>: Send + Sync {
fn spawn_in_context<F>(
future: F,
) -> impl Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send
where
F: Future + Send + 'static,
F::Output: Send + 'static;
fn spawn_from_executor<E, F>(
executor: &E,
future: F,
) -> impl Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send
where
E: Executor<X>,
F: Future + Send + 'static,
F::Output: Send + 'static;
fn block_from_executor<E, F>(executor: &E, future: F) -> impl Future<Output = F::Output> + Send
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>>, 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>>, 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;
}
pub trait Timer: Send + Sync {
fn once(duration_millis: u32) -> impl Future<Output = Self> + Send;
fn interval(duration_millis: u32) -> impl Future<Output = Self> + Send;
fn cancel(&mut self) -> impl Future<Output = ()> + Send;
fn once_sync(duration_millis: u32) -> Self;
fn interval_sync(duration_millis: u32) -> Self;
fn cancel_sync(&mut self);
fn tick(&mut self) -> impl Future<Output = u32> + Send;
}
pub trait Task<Out>: Future
where
Out: Send + 'static,
{
fn output(self) -> Pin<Box<dyn Future<Output = Out> + Send>>;
fn detach(self);
fn drop(self);
}