5 releases

0.1.0 Dec 29, 2023
0.1.0-alpha.5 Oct 20, 2023
0.1.0-alpha.2 May 29, 2023
0.1.0-alpha.1 May 24, 2023
0.0.0 May 19, 2023

#815 in Asynchronous

28 downloads per month

Apache-2.0 OR MIT OR MulanPSL-2.0

42KB
1K SLoC

ARAL - Async Runtime Aggregation Layer

github.com crates.io docs.rs

ARAL is an aggregation layer between your application and the executor for your async stuff. It lets you switch the executors smooth and easy without having to change your applications code.

Runtime

Note: Libraries should not enable any runtime features. You can choose the executor, by using cargo features. There can only be one enabled runtime. Valid features are:

  • runtime-tokio
  • runtime-async-std

Principle

  1. NOT implement async runtime.

    Does not implement a concrete asynchronous runtime, only aggregate out-of-the-box asynchronous runtimes.

  2. Minimum available.

    Try to be as minimal as possible, only add necessary methods, and do not add additional tools (such as channels).

  3. Consistent with std.

    The asynchronous API style should be as consistent as possible with the synchronous API of std.

Example

For libraries, use aral as a dependency and do not enable any runtime-* features.

# Cargo.toml

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
aral = "*"
// lib.rs

use aral::fs::File;
use std::io::Result;

pub async fn is_file(path: &str) -> Result<bool> {
   let file = File::open(path).await?;
   let metadata = file.metadata().await?;
   Ok(metadata.is_file())
}

For application, use aral as a dependency and enable one runtime-* features.

# Cargo.toml

[package]
name = "app"
version = "0.1.0"
edition = "2021"

[dependencies]
aral = { version = "*", features = ["runtime-tokio"] }
tokio = { version = "1.33.0", features = ["full"] }
foo = "0.1.0"
// main.rs

use foo::is_file;

#[tokio::main]
async fn main() {
   let path = "/tmp/some-file.txt";
   println!("{} is file: {:?}", path, is_file(path).await);
}

Now, you can easily switch between async runtimes by enabling other runtime-* features.

License

Apache-2.0 OR MIT OR MulanPSL-2.0

Dependencies

~0–9.5MB
~107K SLoC