-
-
Save hackaugusto/4300a8d016c14b66d4fe702be3970298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt::Display; | |
use std::fmt::Formatter; | |
struct A(u64); | |
impl Display for A { | |
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { | |
write!(fmt, "{}", self.0) | |
} | |
} | |
impl PartialEq for A { | |
fn eq(&self, x: &Self) -> bool { | |
self.0 == x.0 | |
} | |
} | |
impl Eq for A {} | |
impl PartialOrd for A { | |
fn partial_cmp(&self, x: &Self) -> Option<std::cmp::Ordering> { | |
self.0.partial_cmp(&x.0) | |
} | |
} | |
impl Ord for A { | |
fn cmp(&self, x: &Self) -> std::cmp::Ordering { | |
self.0.cmp(&x.0) | |
} | |
} | |
fn main() { | |
let a = A(1); | |
match a { | |
A(0) => { | |
println!("0"); | |
} | |
A(1) => { | |
println!("1"); | |
} | |
x @ _ => { | |
println!("{}", x); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment