#map #macro #error-handling


Closure-less Result::map_err and Option::ok_or_else

2 unstable releases

0.2.0 Jan 1, 2023
0.1.0 Jan 1, 2023

#2993 in Rust patterns

Download history 4/week @ 2024-03-15 38/week @ 2024-03-22 51/week @ 2024-03-29 66/week @ 2024-04-05 95/week @ 2024-04-12 29/week @ 2024-04-19 32/week @ 2024-04-26 6/week @ 2024-05-03 51/week @ 2024-05-10 15/week @ 2024-05-17 8/week @ 2024-05-24 21/week @ 2024-05-31 16/week @ 2024-06-07 25/week @ 2024-06-14 44/week @ 2024-06-21 6/week @ 2024-06-28

98 downloads per month

MIT license

65 lines



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 manual match 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.

No runtime deps