// Copyright (c) 2018 The predicates-rs Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use std::fmt; use crate::reflection; use crate::Predicate; #[derive(Clone, PartialEq, Eq)] pub(crate) struct DebugAdapter where T: fmt::Debug, { pub(crate) debug: T, } impl DebugAdapter where T: fmt::Debug, { pub fn new(debug: T) -> Self { Self { debug } } } impl fmt::Display for DebugAdapter where T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:#?}", self.debug) } } impl fmt::Debug for DebugAdapter where T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.debug.fmt(f) } } pub(crate) fn default_find_case<'a, P, Item>( pred: &'a P, expected: bool, variable: &Item, ) -> Option> where P: Predicate, Item: ?Sized, { let actual = pred.eval(variable); if expected == actual { Some(reflection::Case::new(Some(pred), actual)) } else { None } }