2 unstable releases
0.2.0 | Jan 1, 2023 |
---|---|
0.1.0 | Jan 1, 2023 |
#84 in #error-handling
41 downloads per month
7KB
65 lines
macro-map
lib.rs
:
A small toolbelt of macros that implement the Option::ok_or_else
and
Result::map_err
with macros instead of functions taking callbacks.
This reduces the boilerplate when you can't use the abovementioned functions because the error condition handling logic you need requires you that you move certain values into the closures which you can't affort.
People would normally work around it by .clone()
-ing the value
to be passed into the closure, but that's bad because:
- you need to
.clone()
the item, and that's not always possible; - the
.clone()
is not really necessary, you can rewrite the code with a manualmatch
that would not require and ownership transfers.
But writing a match is vebose, and who wants that?! This is where this crate comes to help.
For best look and feel, combine with
postfix-macros
crate.