From 60c14b1af27aba51c89ae39ffc30fa005045df42 Mon Sep 17 00:00:00 2001 From: Jonathan Goren Date: Wed, 16 Mar 2022 18:38:16 +0200 Subject: [PATCH] make DirEntry Ord --- src/dir_entry.rs | 23 +++++++++++++++++++++++ src/walk.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/dir_entry.rs b/src/dir_entry.rs index 6eae14a..5def5de 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -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 { + self.path().partial_cmp(other.path()) + } +} + +impl Ord for DirEntry { + #[inline] + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.path().cmp(other.path()) + } +} diff --git a/src/walk.rs b/src/walk.rs index 7c22227..463417e 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -310,7 +310,7 @@ impl ReceiverBuffer { /// 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()?; }