Skip to content

Instantly share code, notes, and snippets.

@emidoots
Last active August 29, 2015 14:22
Show Gist options
  • Save emidoots/6ba368a7317140dc2dc2 to your computer and use it in GitHub Desktop.
Save emidoots/6ba368a7317140dc2dc2 to your computer and use it in GitHub Desktop.
// match
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self.x.partial_cmp(&other.x), self.y.partial_cmp(&other.y), self.z.partial_cmp(&other.z), self.w.partial_cmp(&other.w)) {
(Some(Ordering::Less), Some(Ordering::Less), Some(Ordering::Less), Some(Ordering::Less)) => Some(Ordering::Less),
(Some(Ordering::Greater), Some(Ordering::Greater), Some(Ordering::Greater), Some(Ordering::Greater)) => Some(Ordering::Greater),
(Some(Ordering::Equal), Some(Ordering::Equal), Some(Ordering::Equal), Some(Ordering::Equal)) => Some(Ordering::Equal),
_ => None
}
}
// if else
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.x < other.x && self.y < other.y && self.z < other.z && self.w < other.w {
Some(Ordering::Less)
} else if self.x > other.x && self.y > other.y && self.z > other.z && self.w > other.w {
Some(Ordering::Greater)
} else if self == other {
Some(Ordering::Equal)
} else {
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment