derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Feature request: More functions for the `Unwrap` derive?

Open mahmoud-moursy opened this issue 2 years ago • 1 comments

I'd like to see more features from Rust's Option and Result added to the Unwrap derive.

A few notable ones:

  • .map_<variant>(callback_function), a map that will only execute if the Option or Result variant is successful (Some/None).
  • .expect_<variant>(error_msg), an unwrap with a provided error message
  • .unwrap_<variant>_or(fallback), and unwrap that will return the fallback value if the Option or Result were None or Err

mahmoud-moursy avatar Dec 29 '22 19:12 mahmoud-moursy

Those suggested additions seem pretty reasonable. A semi-related issue was added here: https://github.com/JelteF/derive_more/pull/206

I do kind of worry that the amount of methods created by the derive will explode a bit, and thus impact compile time. So it might be nice to have some attributes to opt in/out of generating certain functions. Another option would be to make (some of) these separate derives.

JelteF avatar Dec 29 '22 19:12 JelteF