aboutsummaryrefslogtreecommitdiff
path: root/src/let_else.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/let_else.rs')
-rw-r--r--src/let_else.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/let_else.rs b/src/let_else.rs
new file mode 100644
index 0000000..da17a68
--- /dev/null
+++ b/src/let_else.rs
@@ -0,0 +1,23 @@
+/// Binds the given expression to the given pattern, or else executes
+/// `debug_assert!(false);` with a helpful panic message and returns.
+macro_rules! assume {
+ ($pattern:pat, $value:expr) => {
+ // The expression might change each time it's evaluated, so we
+ // have to bind it so that we can reuse it in the panic message.
+ let _value = $value;
+
+ let $pattern = _value else {
+ debug_assert!(
+ false,
+ "assertion `left matches right` failed:
+ left: {}
+right: {:?}",
+ stringify!($pattern),
+ _value
+ );
+ return;
+ };
+ };
+}
+
+pub(crate) use assume;