decolor

Crates.iodecolor
lib.rsdecolor
version0.1.2
sourcesrc
created_at2023-10-22 18:47:13.918037
updated_at2023-10-22 19:06:29.650486
descriptionAsynchronous runtime abstractions for implicit function decoloring.
homepagehttps://github.com/refcell/decolor
repositoryhttps://github.com/refcell/decolor
max_upload_size
id1010744
size259,122
refcell (refcell)

documentation

README

decolor

Build Status License Docs Latest Version rustc 1.31+

Asynchronous runtime abstractions for implicit function decoloring. Decolor is in https://github.com/refcell/decolor/labels/beta

Install | User Docs | Crate Docs | Reference | Contributing | License

What is decolor?

decolor is a procedural macro crate that implements a #[decolor] attribute macro used to "decolor" an asynchronous rust function. Concretely, the #[decolor] macro can be placed above an asynchronous function to safely1 transform it into a "purple" function (a synchronous function that blocks on asynchronous functionality internally).

1: Constructing the block_on() call in this way prevents nested runtime panics, but calling the Handle block_on method itself panics if the provided future panics or if the runtime on which a timer future is called upon is shut down prior to completion. Additionally, the Runtime's block_on call will panic if it is called from within an asynchronous execution context.

Usage

Add decolor as a dependency with cargo.

cargo add decolor

A short example for building a purple function using the [decolor][decolor] decorator.

use decolor::decolor;
use tokio::time::{sleep, Duration};

#[decolor]
async fn foo() -> anyhow::Result<()> {
    sleep(Duration::from_secs(1)).await;
    println!("Hello, world!");
    Ok(())
}

fn main() {
    assert!(foo().is_ok());
}

Contributing

All contributions are welcome! Experimentation is highly encouraged and new issues are welcome.

Troubleshooting & Bug Reports

Please check existing issues for similar bugs or open an issue if no relevant issue already exists.

License

This project is licensed under the MIT License. Free and open-source, forever. All our rust are belong to you.

Commit count: 10

cargo fmt