Skip to content

Commit

Permalink
refactor(examples): Added ByDuration::duration helper
Browse files Browse the repository at this point in the history
  • Loading branch information
khoover committed Aug 3, 2023
1 parent 5850339 commit 060f348
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions examples/with-metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,31 @@ use smol::{channel, future};

struct ByDuration(Runnable<DurationMetadata>);

impl ByDuration {
fn duration(&self) -> Duration {
self.0.metadata().inner.get()
}
}

impl PartialEq for ByDuration {
fn eq(&self, other: &Self) -> bool {
self.0.metadata().inner.get() == other.0.metadata().inner.get()
self.duration() == other.duration()
}
}

impl Eq for ByDuration {}

impl PartialOrd for ByDuration {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0
.metadata()
.inner
.get()
.partial_cmp(&other.0.metadata().inner.get())
self.duration()
.partial_cmp(&other.duration())
.map(|ord| ord.reverse())
}
}

impl Ord for ByDuration {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0
.metadata()
.inner
.get()
.cmp(&other.0.metadata().inner.get())
.reverse()
self.duration().cmp(&other.duration()).reverse()
}
}

Expand Down

0 comments on commit 060f348

Please sign in to comment.