Skip to content

Instantly share code, notes, and snippets.

@hackaugusto
Created May 24, 2023 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackaugusto/4300a8d016c14b66d4fe702be3970298 to your computer and use it in GitHub Desktop.
Save hackaugusto/4300a8d016c14b66d4fe702be3970298 to your computer and use it in GitHub Desktop.
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