1use core::fmt::{Debug, Display};
2
3use crate::AssertInfo;
4
5mod binary;
6mod collected;
7mod fail;
8mod multi;
9mod should_fail;
10mod succeed;
11mod unary;
12
13#[cfg(feature = "alloc")]
14mod multi_dyn;
15
16pub use binary::BinaryAssertion;
17pub use collected::{AssertAll, CollectedAssertion};
18pub use fail::Fail;
19pub use multi::MultiAssertion;
20pub use should_fail::ShouldFail;
21pub use succeed::Succeed;
22pub use unary::UnaryAssertion;
23
24#[cfg(feature = "alloc")]
25pub use multi_dyn::MultiDynAssertion;
26
27#[cfg(feature = "std")]
28#[must_use = "assertions do not fire unless returned from a test"]
29pub trait Assertion: Debug + Display + std::process::Termination {
31 fn test(&self) -> bool;
33
34 fn should_fail(self) -> ShouldFail<Self>
36 where
37 Self: Sized,
38 {
39 ShouldFail(self)
40 }
41
42 #[allow(
48 clippy::panic,
49 reason = "I agree with you clippy, but some people don't care about panics."
50 )]
51 fn unwrap(&self) {
52 assert!(self.test(), "failed assertion was unwrapped:\n{self}");
53 }
54}
55
56#[cfg(not(feature = "std"))]
57#[must_use = "assertions do not fire unless returned from a test"]
58pub trait Assertion: Debug + Display {
60 fn test(&self) -> bool;
62
63 fn should_fail(self) -> ShouldFail<Self>
65 where
66 Self: Sized,
67 {
68 ShouldFail(self)
69 }
70
71 #[allow(
77 clippy::panic,
78 reason = "I agree with you clippy, but some people don't care about panics."
79 )]
80 fn unwrap(&self) {
81 assert!(self.test(), "failed assertion was unwrapped:\n{self}");
82 }
83}