simulacrum_mock/constraint/
result.rs1use std::fmt;
2
3pub type ConstraintResult = Result<(), ConstraintError>;
5
6#[derive(Clone, Debug, PartialEq)]
7pub enum ConstraintError {
8 AlwaysFail,
9 CalledTooFewTimes(i64),
10 CalledTooManyTimes(i64),
11 CallNotExpected,
12 Custom(String), MismatchedParams(String, String), }
15
16impl fmt::Display for ConstraintError {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 match self {
19 &ConstraintError::AlwaysFail => {
20 write!(f, "Expectation will always fail.")
21 },
22 &ConstraintError::CalledTooFewTimes(times) => {
23 write!(f, "Called {} times fewer than expected.", times)
24 },
25 &ConstraintError::CalledTooManyTimes(times) => {
26 write!(f, "Called {} times more than expected.", times)
27 },
28 &ConstraintError::CallNotExpected => {
29 write!(f, "Called when not expected.")
30 },
31 &ConstraintError::Custom(ref msg) => {
32 write!(f, "{}", msg)
33 },
34 &ConstraintError::MismatchedParams(ref expected_msg, ref received_msg) => {
35 write!(f, "Called with unexpected parameters:\n Expected: {}\n Received: {}", expected_msg, received_msg)
36 },
37 }
38 }
39}