diff --git a/src/file.rs b/src/file.rs index ac3c996..6e9dfb0 100644 --- a/src/file.rs +++ b/src/file.rs @@ -399,6 +399,12 @@ impl<'dir> File<'dir> { } } +impl<'a> AsRef> for File<'a> { + fn as_ref(&self) -> &File<'a> { + &self + } +} + /// Extract the filename to display from a path, converting it from UTF-8 /// lossily, into a String. /// diff --git a/src/options.rs b/src/options.rs index 07af65b..74cbcbb 100644 --- a/src/options.rs +++ b/src/options.rs @@ -349,8 +349,10 @@ impl FileFilter { } /// Sort the files in the given vector based on the sort field option. - pub fn sort_files(&self, files: &mut Vec) { - files.sort_by(|a, b| self.compare_files(a, b)); + pub fn sort_files<'_, F>(&self, files: &mut Vec) + where F: AsRef> { + + files.sort_by(|a, b| self.compare_files(a.as_ref(), b.as_ref())); if self.reverse { files.reverse(); @@ -358,7 +360,7 @@ impl FileFilter { if self.list_dirs_first { // This relies on the fact that `sort_by` is stable. - files.sort_by(|a, b| b.is_directory().cmp(&a.is_directory())); + files.sort_by(|a, b| b.as_ref().is_directory().cmp(&a.as_ref().is_directory())); } } diff --git a/src/output/details.rs b/src/output/details.rs index ed75abf..c663d91 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -229,12 +229,18 @@ impl Details { let mut pool = Pool::new(num_cpus::get() as u32); let mut file_eggs = Vec::new(); - struct Egg<'_> { + struct Egg<'a> { cells: Vec, xattrs: Vec, errors: Vec<(io::Error, Option)>, dir: Option, - file: File<'_>, + file: File<'a>, + } + + impl<'a> AsRef> for Egg<'a> { + fn as_ref(&self) -> &File<'a> { + &self.file + } } pool.scoped(|scoped| { @@ -285,7 +291,7 @@ impl Details { } }); - file_eggs.sort_by(|a, b| self.filter.compare_files(&a.file, &b.file)); + self.filter.sort_files(&mut file_eggs); let num_eggs = file_eggs.len(); for (index, egg) in file_eggs.into_iter().enumerate() {