Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. use std::cmp::PartialOrd;
  2. use std::cmp::Ordering;
  3. use std::cmp::PartialEq;
  4.  
  5. enum Test {
  6.  
  7. Test1,
  8. Test2,
  9. Test3
  10.  
  11. }
  12. fn prio (t: &Test) -> u8 {
  13. match t {
  14. Test::Test1 => 1,
  15. Test::Test2 => 1,
  16. Test::Test3 => 2
  17. }
  18. }
  19. impl PartialOrd for Test {
  20. fn partial_cmp(&self, other: &Test) -> Option<Ordering>{
  21. let prio_of_first = prio(self);
  22. let prio_of_other = prio(&other);
  23. Some(prio_of_first.cmp(&prio_of_other))
  24. }
  25. }
  26. impl PartialEq for Test {
  27. fn eq(&self, other: &Test) -> bool{
  28. let prio_of_first = prio(self);
  29. let prio_of_other = prio(&other);
  30. prio_of_first == prio_of_other
  31. }
  32. }
  33.  
  34. fn main() {
  35.  
  36. println!("{:?}", Test::Test1 < Test::Test3);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement