async_rs/
lib.rs

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