Crates.io | aral |
lib.rs | aral |
version | 0.1.0 |
source | src |
created_at | 2023-05-19 06:35:19.872895 |
updated_at | 2023-12-29 01:38:34.269975 |
description | Async Runtime Aggregation Layer. |
homepage | |
repository | https://github.com/aral-rs/aral.git |
max_upload_size | |
id | 868593 |
size | 47,515 |
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.
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:
NOT implement async runtime.
Does not implement a concrete asynchronous runtime, only aggregate out-of-the-box asynchronous runtimes.
Minimum available.
Try to be as minimal as possible, only add necessary methods, and do not add additional tools (such as channels).
Consistent with std.
The asynchronous API style should be as consistent as possible with the synchronous API of std.
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.
Apache-2.0 OR MIT OR MulanPSL-2.0