pub use otter_base::misc as base_misc;
pub use base_misc::default;
+pub use crate::dbgc;
pub use crate::{deref_to_field, deref_to_field_mut};
pub use crate::ensure_eq;
pub use crate::from_instance_lock_error;
})
}
}
+
+#[macro_export]
+macro_rules! dbgc {
+ // NOTE: We cannot use `concat!` to make a static string as a format argument
+ // of `eprintln!` because `file!` could contain a `{` or
+ // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
+ // will be malformed.
+ () => {
+ std::eprintln!("[{}:{}]", std::file!(), std::line!());
+ };
+ ($val:expr $(,)?) => {
+ // Use of `match` here is intentional because it affects the lifetimes
+ // of temporaries - https://stackoverflow.com/a/48732525/1063961
+ match $val {
+ tmp => {
+ std::eprintln!("[{}:{}] {} = {:?}",
+ std::file!(), std::line!(), std::stringify!($val), &tmp);
+ tmp
+ }
+ }
+ };
+ ($($val:expr),+ $(,)?) => {
+ ($(std::dbg!($val)),+,)
+ };
+}