Allow to compare and sort tasks
This commit is contained in:
parent
ec74847e63
commit
1d6a514e85
1 changed files with 14 additions and 1 deletions
15
src/task.rs
15
src/task.rs
|
@ -1,9 +1,10 @@
|
||||||
use pbkdf2::pbkdf2_hmac;
|
use pbkdf2::pbkdf2_hmac;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
const DUMMY_SALT: &[u8] = b"some dummy salt";
|
const DUMMY_SALT: &[u8] = b"some dummy salt";
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub data: &'static [u8],
|
pub data: &'static [u8],
|
||||||
pub cost: u32,
|
pub cost: u32,
|
||||||
|
@ -19,3 +20,15 @@ impl Task {
|
||||||
pbkdf2_hmac::<Sha256>(self.data, DUMMY_SALT, self.cost, &mut key1);
|
pbkdf2_hmac::<Sha256>(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<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue