Crates.io | ferris-extensions |
lib.rs | ferris-extensions |
version | 0.1.0 |
source | src |
created_at | 2020-05-16 20:41:39.733668 |
updated_at | 2020-05-16 20:41:39.733668 |
description | Extension macros for Rust |
homepage | |
repository | https://github.com/redradist/ferris-extensions |
max_upload_size | |
id | 242492 |
size | 20,241 |
This macro #[boxed_async_recursion]
is for helping recursion calls with async/.await
Previously for writing recursion with async/.await you should make the following trick:
fn recursive(k: u8, l: u32) -> BoxFuture<'static, u8> {
async move {
recursive(k, l).await;
recursive(k, l).await;
2u8
}.boxed()
}
With this crate it is possible to simplify code as follows:
#[boxed_async_recursion]
async fn recursive(k: u8, l: u32) -> u8 {
recursive(k, l).await;
recursive(k, l).await;
2u8
}
Under the hood compiler macros still generates BoxFuture and async move, but it much easy to understand code right know
This macro #[multiple_result_errors]
is for helping handle multiple errors from functions
Example:
#[multiple_result_errors]
fn handle_file() -> Result<(), (IOError, IOError2)>
{
get_io_error()?;
Ok(())
}
fn main() {
let res = handle_file();
match res {
Ok(t) => {},
Err(err) => {
match err {
HandleFileResultErrors::IOError(err0) => {},
HandleFileResultErrors::IOError2(err1) => {},
};
}
};
}
In this example with help of macros #[multiple_result_errors]
will be generated anonymous enum Handle22UrlResultErrors
that simplify working with multiple errors