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

Consider allowing 1-argument ensure! #126

Closed
dtolnay opened this issue Nov 15, 2020 · 0 comments · Fixed by #129
Closed

Consider allowing 1-argument ensure! #126

dtolnay opened this issue Nov 15, 2020 · 0 comments · Fixed by #129

Comments

@dtolnay
Copy link
Owner

dtolnay commented Nov 15, 2020

The ensure! macro currently takes a condition argument (bool) followed by format arguments for the error message.
https://docs.rs/anyhow/1.0.34/anyhow/macro.ensure.html

    ($cond:expr, $fmt:expr, $($arg:tt)*) => { ... };

It would be reasonable to also support 1-argument ensure! with only the condition argument.

ensure!(depth <= MAX_DEPTH);

If the condition is false, the resulting error would be produced from the stringify of the condition expression. This would match the API of the standard library's assert! macro. https://doc.rust-lang.org/std/macro.assert.html

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 a pull request may close this issue.

1 participant