predicates/
utils.rs
1use std::fmt;
10
11use crate::reflection;
12use crate::Predicate;
13
14#[derive(Clone, PartialEq, Eq)]
15pub(crate) struct DebugAdapter<T>
16where
17 T: fmt::Debug,
18{
19 pub(crate) debug: T,
20}
21
22impl<T> DebugAdapter<T>
23where
24 T: fmt::Debug,
25{
26 pub fn new(debug: T) -> Self {
27 Self { debug }
28 }
29}
30
31impl<T> fmt::Display for DebugAdapter<T>
32where
33 T: fmt::Debug,
34{
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 write!(f, "{:#?}", self.debug)
37 }
38}
39
40impl<T> fmt::Debug for DebugAdapter<T>
41where
42 T: fmt::Debug,
43{
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 self.debug.fmt(f)
46 }
47}
48
49pub(crate) fn default_find_case<'a, P, Item>(
50 pred: &'a P,
51 expected: bool,
52 variable: &Item,
53) -> Option<reflection::Case<'a>>
54where
55 P: Predicate<Item>,
56 Item: ?Sized,
57{
58 let actual = pred.eval(variable);
59 if expected == actual {
60 Some(reflection::Case::new(Some(pred), actual))
61 } else {
62 None
63 }
64}