Crates.io | decolor |
lib.rs | decolor |
version | 0.1.2 |
source | src |
created_at | 2023-10-22 18:47:13.918037 |
updated_at | 2023-10-22 19:06:29.650486 |
description | Asynchronous runtime abstractions for implicit function decoloring. |
homepage | https://github.com/refcell/decolor |
repository | https://github.com/refcell/decolor |
max_upload_size | |
id | 1010744 |
size | 259,122 |
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
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.
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());
}
All contributions are welcome! Experimentation is highly encouraged and new issues are welcome.
Please check existing issues for similar bugs or open an issue if no relevant issue already exists.
This project is licensed under the MIT License. Free and open-source, forever. All our rust are belong to you.