lool » macros is a collection of utility macros for rust.
Installation
This crate is for internal use. It's only published privately.
cargo add lool --registry=lugit --features macros
Macros
s
A macro to create a String from a &str.
use lool::s;
fn main() {
let s = s!("Hello, world!");
// now `s` is a `String`
}
f or fail
A macro to use with the eyre crate.
It basically creates an Err.
It's almost the same as bail! from the anyhow crate, but this one doesn't explicitly returns (the bail! macro creates a return statement).
This macro is equivalent to: Err(eyre!(<args>)).
use lool::f;
fn main() -> eyre::Result<()> {
if (2 + 2) == 5 {
f!("Oh no! I'm bad at math!");
}
Ok(())
}
which is equivalent to:
use eyre::eyre;
fn main() -> eyre::Result<()> {
if (2 + 2) == 5 {
return Err(eyre!("Oh no! I'm bad at math!"));
}
Ok(())
}
It also works as a final statement:
use lool::f;
fn fail_always() -> eyre::Result<()> {
// no ; at the end
f!("I'm a failure")
}