Macro trackable::track_assert
[−]
[src]
macro_rules! track_assert { ($cond:expr, $error_kind:expr) => { ... }; ($cond:expr, $error_kind:expr, $($format_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()), r#" Failed (cause; assertion failed: a > 0.0 && b > 0.0) HISTORY: [0] at <anon>:8 "#);