Macro trackable::track_assert
[−]
[src]
macro_rules! track_assert { ($cond:expr, $error_kind:expr) => { ... }; ($cond:expr, $error_kind:expr, $fmt:expr) => { ... }; ($cond:expr, $error_kind:expr, $fmt:expr, $($arg:tt)*) => { ... }; }
Error trackable variant of the standard assert!
macro.
This is a simple wrapper of the track_panic!
macro.
It will call track_panic!($error_kind, $($format_arg)+)
if $cond
is evaluated to false
.
Examples
use trackable::error::{Failed, Failure}; fn add_positive_f32(a: f32, b: f32) -> Result<f32, Failure> { track_assert!(a > 0.0 && b > 0.0, Failed); Ok(a + b) } let r = add_positive_f32(3.0, 2.0); // Ok assert_eq!(r.ok(), Some(5.0)); let r = add_positive_f32(1.0, -2.0); // Err assert!(r.is_err()); assert_eq!(format!("\n{}", r.err().unwrap()).replace('\\', "/"), r#" Failed (cause; assertion failed: `a > 0.0 && b > 0.0`) HISTORY: [0] at src/macros.rs:8 "#);