make DirEntry Ord

This commit is contained in:
Jonathan Goren 2022-03-16 18:38:16 +02:00
parent 47e30d3d4a
commit 60c14b1af2
2 changed files with 24 additions and 1 deletions

View file

@ -16,6 +16,7 @@ pub struct DirEntry {
}
impl DirEntry {
#[inline]
pub fn normal(e: ignore::DirEntry) -> Self {
Self {
inner: DirEntryInner::Normal(e),
@ -67,3 +68,25 @@ impl DirEntry {
}
}
}
impl PartialEq for DirEntry {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.path() == other.path()
}
}
impl Eq for DirEntry {}
impl PartialOrd for DirEntry {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.path().partial_cmp(other.path())
}
}
impl Ord for DirEntry {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.path().cmp(other.path())
}
}

View file

@ -310,7 +310,7 @@ impl<W: Write> ReceiverBuffer<W> {
/// Stop looping.
fn stop(&mut self) -> Result<(), ExitCode> {
if self.mode == ReceiverMode::Buffering {
self.buffer.sort_by(|e1, e2| e1.path().cmp(e2.path()));
self.buffer.sort();
self.stream()?;
}