Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cmp::PartialOrd;
- use std::cmp::Ordering;
- use std::cmp::PartialEq;
- enum Test {
- Test1,
- Test2,
- Test3
- }
- fn prio (t: &Test) -> u8 {
- match t {
- Test::Test1 => 1,
- Test::Test2 => 1,
- Test::Test3 => 2
- }
- }
- impl PartialOrd for Test {
- fn partial_cmp(&self, other: &Test) -> Option<Ordering>{
- let prio_of_first = prio(self);
- let prio_of_other = prio(&other);
- Some(prio_of_first.cmp(&prio_of_other))
- }
- }
- impl PartialEq for Test {
- fn eq(&self, other: &Test) -> bool{
- let prio_of_first = prio(self);
- let prio_of_other = prio(&other);
- prio_of_first == prio_of_other
- }
- }
- fn main() {
- println!("{:?}", Test::Test1 < Test::Test3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement