From 37ad364f6421c0de2fc3a502d74e3bd68a9d3163 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 5 Apr 2024 06:39:44 -0400 Subject: [PATCH] chore: workspace support and sort dependencies, fmt, spelling --- Cargo.toml | 10 +++-- cmd/qbsdiff.rs | 2 +- src/bsdiff.rs | 2 - src/bspatch.rs | 2 +- utils/src/lib.rs | 112 ++++++++++++++++++----------------------------- 5 files changed, 52 insertions(+), 76 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86ba185..5e4541e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,7 @@ +[workspace] +members = [".", "utils"] +default-members = [".", "utils"] + [package] name = "qbsdiff" version = "1.4.1" @@ -16,11 +20,11 @@ bzip2 = "0.4.4" byteorder = "1.4" rayon = "1.5" suffix_array = "0.5" -clap = { optional = true, version = "3.2", features = [ "derive" ] } +clap = { optional = true, version = "3.2", features = ["derive"] } [dev-dependencies] -qbsdiff_test_bench_utils = { version ="0.1", path = "utils" } -criterion = { version = "0.3", features = [ "html_reports" ] } +qbsdiff_test_bench_utils = { version = "0.1", path = "utils" } +criterion = { version = "0.3", features = ["html_reports"] } [features] default = [] diff --git a/cmd/qbsdiff.rs b/cmd/qbsdiff.rs index e01e1e9..53dc607 100644 --- a/cmd/qbsdiff.rs +++ b/cmd/qbsdiff.rs @@ -58,7 +58,7 @@ fn main() { fn execute(args: BsdiffArgs) -> io::Result<()> { // validate command line arguments - if !(matches!(args.compress_level, Some(0..=9) | None)) { + if !matches!(args.compress_level, Some(0..=9) | None) { return Err(io::Error::new( io::ErrorKind::Other, "compression level must be in range 0-9", diff --git a/src/bsdiff.rs b/src/bsdiff.rs index e4a9b4f..118a778 100644 --- a/src/bsdiff.rs +++ b/src/bsdiff.rs @@ -177,8 +177,6 @@ impl<'s, 't> Bsdiff<'s, 't> { /// The fastest/default compression level is usually good enough. /// In contrast, patch files produced with the best level appeared slightly /// bigger in many test cases. - /// - /// [struct]: bzip2::Compression pub fn compression_level(mut self, compression_level: u32) -> Self { self.compression_level = Compression::new(u32::min(u32::max(compression_level, 0), 9)); self diff --git a/src/bspatch.rs b/src/bspatch.rs index 23edfa5..a71893e 100644 --- a/src/bspatch.rs +++ b/src/bspatch.rs @@ -254,7 +254,7 @@ impl<'s, 'p, T: Write> Context<'s, 'p, T> { /// Move the cursor on source. fn seek(&mut self, offset: i64) -> Result<()> { - self.source.seek(SeekFrom::Current(offset)).map(std::mem::drop) + self.source.seek(SeekFrom::Current(offset)).map(drop) } } diff --git a/utils/src/lib.rs b/utils/src/lib.rs index 60c702b..e421c2a 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -56,7 +56,7 @@ pub struct Testing { } impl Testing { - /// Create new tesing context. + /// Create new testing context. pub fn new(assets_dir: path::PathBuf) -> Self { Testing { assets_dir } } @@ -137,7 +137,11 @@ impl Testing { run_command_in( dir, "bsdiff", - &[sample.source.as_os_str(), sample.target.as_os_str(), sample.patch.as_os_str()], + &[ + sample.source.as_os_str(), + sample.target.as_os_str(), + sample.patch.as_os_str(), + ], )?; } fs::read(sample.patch.as_path()) @@ -216,14 +220,17 @@ impl Benchmarking { run_command_in( dir, "bsdiff", - &[sample.source.as_os_str(), sample.target.as_os_str(), sample.patch.as_os_str()], + &[ + sample.source.as_os_str(), + sample.target.as_os_str(), + sample.patch.as_os_str(), + ], )?; } else { let mut patch = Vec::new(); let source = fs::read(sample.source.as_path())?; let target = fs::read(sample.target.as_path())?; - Bsdiff::new(&source[..], &target[..]) - .compare(io::Cursor::new(&mut patch))?; + Bsdiff::new(&source[..], &target[..]).compare(io::Cursor::new(&mut patch))?; patch.shrink_to_fit(); fs::write(sample.patch.as_path(), &patch[..])?; return Ok(patch); @@ -233,7 +240,8 @@ impl Benchmarking { } fn should_use_bsdiff(&self, sample: &Sample) -> bool { - sample.patch + sample + .patch .parent() .and_then(|p| p.file_name()) .map(|d| d == "samples") @@ -266,9 +274,9 @@ fn run_bspatch_in>(dir: P, s: &[u8], p: &[u8]) -> io::Result(dir: P, cmd: &str, args: &[S]) -> io::Result<()> - where - P: AsRef, - S: AsRef, +where + P: AsRef, + S: AsRef, { let bin = get_binary_in(dir, cmd)?; let mut proc = process::Command::new(&bin) @@ -278,20 +286,24 @@ fn run_command_in(dir: P, cmd: &str, args: &[S]) -> io::Result<()> .spawn()?; let mut errors = String::new(); - let mut stderr = proc.stderr.take() + let mut stderr = proc + .stderr + .take() .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "failed to get command stderr"))?; stderr.read_to_string(&mut errors)?; let status = proc.wait()?; if !status.success() { - let message = format!("command [{} {}], {}, stderr:\n{}", - bin.to_string_lossy(), - args.iter() - .map(|arg| arg.as_ref().to_string_lossy()) - .collect::>() - .join(" "), - status, - errors); + let message = format!( + "command [{} {}], {}, stderr:\n{}", + bin.to_string_lossy(), + args.iter() + .map(|arg| arg.as_ref().to_string_lossy()) + .collect::>() + .join(" "), + status, + errors + ); return Err(io::Error::new(io::ErrorKind::Other, message)); } else { Ok(()) @@ -346,15 +358,10 @@ fn get_samples_in>(dir: P) -> io::Result> { if let Some(p) = pat.to_str() { walker = glob(p).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; } else { - return Err(io::Error::new( - io::ErrorKind::Other, - "cannot convert to str", - )); + return Err(io::Error::new(io::ErrorKind::Other, "cannot convert to str")); } for result in walker.into_iter() { - let source = result - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))? - .into_path(); + let source = result.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?.into_path(); let name; let target; @@ -371,10 +378,7 @@ fn get_samples_in>(dir: P) -> io::Result> { pbuf.push(".p"); patch = path::PathBuf::from(d).join(pbuf.as_os_str()); } else { - return Err(io::Error::new( - io::ErrorKind::Other, - "cannot make target or patch path", - )); + return Err(io::Error::new(io::ErrorKind::Other, "cannot make target or patch path")); } if let Err(_) = fs::metadata(target.as_path()) { @@ -417,10 +421,8 @@ fn get_random_caches_in>(dir: P, descs: &[RandomSample]) -> io::R let target = dir.as_ref().join(format!("{}.{}.t", desc.name, tdesc.name(id))); if !exists_file(target.as_path()) { match tdesc { - RandomTarget::Bytes(bytes) => - fs::write(target.as_path(), bytes)?, - RandomTarget::Distort(rate) => - fs::write(target.as_path(), &distort(&sdata[..], *rate)[..])?, + RandomTarget::Bytes(bytes) => fs::write(target.as_path(), bytes)?, + RandomTarget::Distort(rate) => fs::write(target.as_path(), &distort(&sdata[..], *rate)[..])?, } } let patch = dir.as_ref().join(format!("{}.{}.p", desc.name, tdesc.name(id))); @@ -483,13 +485,13 @@ r incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis no\ strud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Dui\ s aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fu\ giat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in cu\ -lpa qui officia deserunt mollit anim id est laborum." +lpa qui officia deserunt mollit anim id est laborum.", ), targets: vec![ TBytes(b""), TBytes( b"consectetur adip##cing elit, jed do eiusmod wir mussen wissen. wir werden wis\ -sen/ laboris nisi ut al&^%ip ex ea coikodo consequat. " +sen/ laboris nisi ut al&^%ip ex ea coikodo consequat. ", ), TBytes(b"the quick brown fox jumps over the lazy dog"), Distort(0.0), @@ -500,42 +502,22 @@ sen/ laboris nisi ut al&^%ip ex ea coikodo consequat. " RandomSample { name: "rand-4k", source: Random(4096), - targets: vec![ - TBytes(b""), - Distort(0.0), - Distort(0.5), - Distort(1.0), - ], + targets: vec![TBytes(b""), Distort(0.0), Distort(0.5), Distort(1.0)], }, RandomSample { name: "rand-256k", source: Random(256 * 1024), - targets: vec![ - TBytes(b""), - Distort(0.0), - Distort(0.5), - Distort(1.0), - ], + targets: vec![TBytes(b""), Distort(0.0), Distort(0.5), Distort(1.0)], }, RandomSample { name: "rand-1m", source: Random(1024 * 1024), - targets: vec![ - TBytes(b""), - Distort(0.0), - Distort(0.5), - Distort(1.0), - ], + targets: vec![TBytes(b""), Distort(0.0), Distort(0.5), Distort(1.0)], }, RandomSample { name: "rand-8m", source: Random(8 * 1024 * 1024), - targets: vec![ - TBytes(b""), - Distort(0.0), - Distort(0.5), - Distort(1.0), - ], + targets: vec![TBytes(b""), Distort(0.0), Distort(0.5), Distort(1.0)], }, ] } @@ -549,20 +531,12 @@ pub fn default_random_bench_samples() -> Vec { RandomSample { name: "rand-512k", source: Random(512 * 1024), - targets: vec![ - Distort(0.05), - Distort(0.50), - Distort(0.95), - ], + targets: vec![Distort(0.05), Distort(0.50), Distort(0.95)], }, RandomSample { name: "rand-4m", source: Random(4 * 1024 * 1024), - targets: vec![ - Distort(0.05), - Distort(0.50), - Distort(0.95), - ], + targets: vec![Distort(0.05), Distort(0.50), Distort(0.95)], }, ] }