diff --git a/src/task.rs b/src/task.rs index 8fac2b2..3b4c2e6 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,9 +1,10 @@ use pbkdf2::pbkdf2_hmac; use sha2::Sha256; +use std::cmp::Ordering; const DUMMY_SALT: &[u8] = b"some dummy salt"; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct Task { pub data: &'static [u8], pub cost: u32, @@ -19,3 +20,15 @@ impl Task { pbkdf2_hmac::(self.data, DUMMY_SALT, self.cost, &mut key1); } } + +impl Ord for Task { + fn cmp(&self, other: &Self) -> Ordering { + self.cost.cmp(&other.cost) + } +} + +impl PartialOrd for Task { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +}