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