Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. use std::fmt;
  2. use std::any::Any;
  3. use std::fmt::Debug;
  4.  
  5.  
  6. pub type AssertResult = Result<(), String>;
  7.  
  8. pub trait Assert<L: Any + Debug> {
  9. fn compare<R: Any + Debug>(self, target: R) -> AssertResult;
  10. }
  11.  
  12. pub struct Equal<L> {
  13. expected: L,
  14. }
  15.  
  16. impl<L> Equal<L> {
  17. pub fn new(expected: L) -> Equal<L> {
  18. Equal { expected: expected }
  19. }
  20. }
  21.  
  22. impl<L: 'static + fmt::Debug> Assert<L> for Equal<L> {
  23. fn compare<R: PartialEq<L> + fmt::Debug>(self, target: R) -> AssertResult {
  24. if target == self.expected {
  25. Ok(())
  26. } else {
  27. Err(format!(
  28. "Expected {:?}, recei222ved {:?}",
  29. self.expected,
  30. target
  31. ))
  32. }
  33. }
  34. }
  35.  
  36.  
  37. fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement