#async #macro #proc-macro #color #library

macro decolor

Asynchronous runtime abstractions for implicit function decoloring

3 releases

0.1.2 Oct 22, 2023
0.1.1 Oct 22, 2023
0.1.0 Oct 22, 2023

#1484 in Procedural macros

MIT license

225KB

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.

Dependencies

~2.7–8.5MB
~77K SLoC