Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A convenience macro to unwrap an option with a general message #393

Closed
wants to merge 1 commit into from

Conversation

imbolc
Copy link

@imbolc imbolc commented Nov 19, 2024

let foo = unwrap_some!(maybe_foo);

/// Instead of
let foo = maybe_foo.context("`maybe_foo` is `None`")?;

Some APIs, e.g. aws_sdk, assume extensive unwrapping of options. This macro is meant to avoid the repetition of variable names in context messages.

I'm not sure about the naming. Other options are:

  • ensure_some - but it seems inconsistent with the ensure! macro, which doesn't return anything
  • unwrap_opt
  • unwrap_option

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! But I would prefer not to support this in this library.

@dtolnay dtolnay closed this Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants