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, sync::Arc, time::Duration};
18//!
19//! async fn get_a(rt: Arc<TokioRuntime>) -> io::Result<u32> {
20//!     rt.clone()
21//!         .spawn_blocking(move || rt.block_on(async { Ok(12) }))
22//!         .await
23//! }
24//!
25//! async fn get_b(rt: Arc<TokioRuntime>) -> io::Result<u32> {
26//!     rt.spawn(async { Ok(30) }).await
27//! }
28//!
29//! async fn tokio_main() -> io::Result<()> {
30//!     let rt = Arc::new(Runtime::tokio());
31//!     let a = get_a(rt.clone()).await?;
32//!     let b = get_b(rt.clone()).await?;
33//!     rt.sleep(Duration::from_millis(500)).await;
34//!     assert_eq!(a + b, 42);
35//!     Ok(())
36//! }
37//!
38//! #[tokio::main]
39//! async fn main() -> io::Result<()> {
40//!     tokio_main().await
41//! }
42//! ```
43
44mod runtime;
45pub use runtime::*;
46
47pub mod traits;
48
49mod implementors;
50pub use implementors::*;
51
52pub mod util;
53
54mod sys;