1use std::fmt;
12
13pub type MatchResult = Result<(), String>;
14
15pub fn success() -> MatchResult {
16 Ok(())
17}
18
19pub fn expect(predicate: bool, msg: String) -> MatchResult {
20 if predicate { success() } else { Err(msg) }
21}
22
23#[deprecated(since = "0.1.2", note = "Use the assert_that! macro instead")]
24pub fn assert_that<T, U: Matcher<T>>(actual: T, matcher: U) {
25 match matcher.matches(actual) {
26 Ok(_) => return,
27 Err(mismatch) => {
28 panic!("\nExpected: {}\n but: {}", matcher, mismatch);
29 }
30 }
31}
32
33pub trait Matcher<T>: fmt::Display {
34 fn matches(&self, actual: T) -> MatchResult;
35}