Crate macro_map

source ·
Expand description

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.

Macros

An analog to Result::map_err but without a closure.
An analog to Option::ok_or_else but without a closure.
An analog to Result::map_err followed by a ? but without a closure.
An analog to Result::map_err followed by a ? but without a closure.