#![allow(dead_code, deprecated, unused_variables, unused_mut)] use std::cmp::Ordering; #[derive(Debug)] struct Character { health: f32, } impl Ord for Character { fn cmp(&self, other: &Self) -> std::cmp::Ordering { if self.health < other.health { Ordering::Less } else if self.health > other.health { Ordering::Greater } else { Ordering::Equal } } } impl PartialOrd for Character { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl PartialEq for Character { fn eq(&self, other: &Self) -> bool { self.health == other.health } } impl Eq for Character {} fn main() { let a = Character { health: 4.5 }; let b = Character { health: f32::NAN }; assert!(a == a); assert!(b != b); assert_eq!((a < b) as u8 + (b < a) as u8, 0); }