From 2d4135be9c48b2d68d14153d62744db5498d1574 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Tue, 15 Oct 2024 15:12:36 +0200 Subject: [PATCH] various: more clippy --- src/dumpfile.rs | 10 +++++----- src/image.rs | 4 ++-- src/oci/image.rs | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/dumpfile.rs b/src/dumpfile.rs index 921edc5..fdc0033 100644 --- a/src/dumpfile.rs +++ b/src/dumpfile.rs @@ -149,7 +149,7 @@ impl<'a, W: Write> DumpfileWriter<'a, W> { Self { hardlinks: HashMap::new(), writer } } - fn write_dir(&mut self, mut path: &mut PathBuf, dir: &Directory) -> Result<()> { + fn write_dir(&mut self, path: &mut PathBuf, dir: &Directory) -> Result<()> { // nlink is 2 + number of subdirectories // this is also true for the root dir since '..' is another self-ref let nlink = dir.entries.iter().fold(2, |count, ent| count + { @@ -166,10 +166,10 @@ impl<'a, W: Write> DumpfileWriter<'a, W> { match inode { Inode::Directory(ref dir) => { - self.write_dir(&mut path, dir)?; + self.write_dir(path, dir)?; }, Inode::Leaf(ref leaf) => { - self.write_leaf(&path, leaf)?; + self.write_leaf(path, leaf)?; } } @@ -185,14 +185,14 @@ impl<'a, W: Write> DumpfileWriter<'a, W> { // This is a hardlink. We need to handle that specially. let ptr = Rc::as_ptr(leaf); if let Some(target) = self.hardlinks.get(&ptr) { - return writeln_fmt(self.writer, |fmt| write_hardlink(fmt, &path, target)); + return writeln_fmt(self.writer, |fmt| write_hardlink(fmt, path, target)); } // @path gets modified all the time, so take a copy self.hardlinks.insert(ptr, OsString::from(&path)); } - writeln_fmt(self.writer, |fmt| write_leaf(fmt, &path, &leaf.stat, &leaf.content, nlink)) + writeln_fmt(self.writer, |fmt| write_leaf(fmt, path, &leaf.stat, &leaf.content, nlink)) } } diff --git a/src/image.rs b/src/image.rs index 766b0cb..6a79e79 100644 --- a/src/image.rs +++ b/src/image.rs @@ -71,8 +71,8 @@ impl Directory { // iteration of the binary search. if let Some(last_entry) = self.entries.last() { match name.cmp(&last_entry.name) { - Ordering::Equal => return Ok(self.entries.len() - 1), // the last item, indeed - Ordering::Greater => return Err(self.entries.len()), // need to append + Ordering::Equal => Ok(self.entries.len() - 1), // the last item, indeed + Ordering::Greater => Err(self.entries.len()), // need to append Ordering::Less => self.entries.binary_search_by_key(&name, |e| &e.name) } } else { diff --git a/src/oci/image.rs b/src/oci/image.rs index 5a1ae63..bd2c40d 100644 --- a/src/oci/image.rs +++ b/src/oci/image.rs @@ -33,9 +33,8 @@ pub fn process_entry(filesystem: &mut FileSystem, entry: oci::tar::TarEntry) -> let mut dir = &mut filesystem.root; for component in components { - match component { - Component::Normal(name) => { dir = dir.recurse(name)?; }, - _ => { } + if let Component::Normal(name) = component { + dir = dir.recurse(name)?; } } @@ -153,7 +152,7 @@ fn assert_files(fs: &FileSystem, expected: &[&str]) -> Result<()> { write_dumpfile(&mut out, fs)?; let actual: Vec = out .lines() - .map(|line| line.unwrap().split_once(|c| c == ' ').unwrap().0.into() ) + .map(|line| line.unwrap().split_once(' ').unwrap().0.into() ) .collect(); assert_eq!(actual, expected);