async_rs/
lib.rs

1#![deny(missing_docs, missing_debug_implementations, unsafe_code)]
2#![allow(clippy::manual_async_fn)]
3
4//! A Rust async runtime abstration library.
5//!
6//! ## Features
7//!
8//! - tokio: enable the tokio implementation *(default)*
9//! - smol: enable the smol implementation
10//! - async-global-executor: enable the async-global-executor implementation
11//! - async-io: enable the async-io reactor implementation
12//!
13//! ## Example
14//!
15//! ```rust
16//! use async_rs::{Runtime, TokioRuntime, traits::*};
17//! use std::{io, time::Duration};
18//!
19//! async fn get_a(rt: &TokioRuntime) -> io::Result<u32> {
20//!     rt.spawn_blocking(|| Ok(12)).await
21//! }
22//!
23//! async fn get_b(rt: &TokioRuntime) -> io::Result<u32> {
24//!     rt.spawn(async { Ok(30) }).await
25//! }
26//!
27//! async fn tokio_main(rt: &TokioRuntime) -> io::Result<()> {
28//!     let a = get_a(&rt).await?;
29//!     let b = get_b(&rt).await?;
30//!     rt.sleep(Duration::from_millis(500)).await;
31//!     assert_eq!(a + b, 42);
32//!     Ok(())
33//! }
34//!
35//! fn main() -> io::Result<()> {
36//!     let rt = Runtime::tokio()?;
37//!     rt.block_on(tokio_main(&rt))
38//! }
39//! ```
40
41mod runtime;
42pub use runtime::*;
43
44pub mod traits;
45
46mod implementors;
47#[cfg(any(
48    feature = "async-global-executor",
49    feature = "async-io",
50    feature = "hickory-dns",
51    feature = "smol",
52    feature = "tokio"
53))]
54pub use implementors::*;
55
56pub mod util;
57
58mod sys;