aral

Crates.ioaral
lib.rsaral
version0.1.0
sourcesrc
created_at2023-05-19 06:35:19.872895
updated_at2023-12-29 01:38:34.269975
descriptionAsync Runtime Aggregation Layer.
homepage
repositoryhttps://github.com/aral-rs/aral.git
max_upload_size
id868593
size47,515
jmjoy (jmjoy)

documentation

README

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

Commit count: 29

cargo fmt