decolor
Asynchronous runtime abstractions for implicit function decoloring. Decolor is in 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.