mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
feat: {ensure_and,logged}_debug_assert: Don't evaluate condition twice
This commit is contained in:
12
src/tools.rs
12
src/tools.rs
@@ -767,9 +767,10 @@ pub(crate) fn inc_and_check<T: PrimInt + AddAssign + std::fmt::Debug>(
|
||||
/// In non-optimized builds, panics instead if so.
|
||||
#[macro_export]
|
||||
macro_rules! ensure_and_debug_assert {
|
||||
($($arg:tt)*) => {
|
||||
debug_assert!($($arg)*);
|
||||
anyhow::ensure!($($arg)*);
|
||||
($cond:expr, $($arg:tt)*) => {
|
||||
let cond_val = $cond;
|
||||
debug_assert!(cond_val, $($arg)*);
|
||||
anyhow::ensure!(cond_val, $($arg)*);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -806,10 +807,11 @@ macro_rules! ensure_and_debug_assert_ne {
|
||||
#[macro_export]
|
||||
macro_rules! logged_debug_assert {
|
||||
($ctx:expr, $cond:expr, $($arg:tt)*) => {
|
||||
if !$cond {
|
||||
let cond_val = $cond;
|
||||
if !cond_val {
|
||||
warn!($ctx, $($arg)*);
|
||||
}
|
||||
debug_assert!($cond, $($arg)*);
|
||||
debug_assert!(cond_val, $($arg)*);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user