aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2023-09-16 19:17:58 -0700
committerJack O'Connor <[email protected]>2023-09-16 19:22:36 -0700
commitb754033a2187c509ee1b29facea31ae13d122904 (patch)
tree626600ef973df12cbbdb9809bc3aa66de0912f51
parentcb32f0bd1450991d86a8ceb3716fd591382cc507 (diff)
make update_reader/mmap/mmap_rayon return self
This makes them consistent with how the existing update() and update_rayon() methods work, with the difference being that it's it's io::Result<&mut Self> instead of just &mut Self.
-rw-r--r--src/lib.rs16
-rw-r--r--src/test.rs27
2 files changed, 28 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1a2d22d..5b03ff9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1346,8 +1346,9 @@ impl Hasher {
/// # }
/// ```
#[cfg(feature = "std")]
- pub fn update_reader(&mut self, reader: impl std::io::Read) -> std::io::Result<u64> {
- io::copy_wide(reader, self)
+ pub fn update_reader(&mut self, reader: impl std::io::Read) -> std::io::Result<&mut Self> {
+ io::copy_wide(reader, self)?;
+ Ok(self)
}
/// As [`update`](Hasher::update), but using Rayon-based multithreading
@@ -1417,14 +1418,14 @@ impl Hasher {
/// # }
/// ```
#[cfg(feature = "mmap")]
- pub fn update_mmap(&mut self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
+ pub fn update_mmap(&mut self, path: impl AsRef<std::path::Path>) -> std::io::Result<&mut Self> {
let file = std::fs::File::open(path.as_ref())?;
if let Some(mmap) = io::maybe_mmap_file(&file)? {
self.update(&mmap);
} else {
io::copy_wide(&file, self)?;
}
- Ok(())
+ Ok(self)
}
/// As [`update_rayon`](Hasher::update_rayon), but reading the contents of a file using
@@ -1469,14 +1470,17 @@ impl Hasher {
/// ```
#[cfg(feature = "mmap")]
#[cfg(feature = "rayon")]
- pub fn update_mmap_rayon(&mut self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
+ pub fn update_mmap_rayon(
+ &mut self,
+ path: impl AsRef<std::path::Path>,
+ ) -> std::io::Result<&mut Self> {
let file = std::fs::File::open(path.as_ref())?;
if let Some(mmap) = io::maybe_mmap_file(&file)? {
self.update_rayon(&mmap);
} else {
io::copy_wide(&file, self)?;
}
- Ok(())
+ Ok(self)
}
}
diff --git a/src/test.rs b/src/test.rs
index a319930..c98192f 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -701,9 +701,12 @@ fn test_update_reader() -> Result<(), std::io::Error> {
let mut tempfile = tempfile::NamedTempFile::new()?;
tempfile.write_all(&input)?;
tempfile.flush()?;
- let mut hasher = crate::Hasher::new();
- hasher.update_reader(std::fs::File::open(tempfile.path())?)?;
- assert_eq!(hasher.finalize(), crate::hash(&input));
+ assert_eq!(
+ crate::Hasher::new()
+ .update_reader(std::fs::File::open(tempfile.path())?)?
+ .finalize(),
+ crate::hash(&input),
+ );
Ok(())
}
@@ -755,9 +758,12 @@ fn test_mmap() -> Result<(), std::io::Error> {
let mut tempfile = tempfile::NamedTempFile::new()?;
tempfile.write_all(&input)?;
tempfile.flush()?;
- let mut hasher = crate::Hasher::new();
- hasher.update_mmap(tempfile.path())?;
- assert_eq!(hasher.finalize(), crate::hash(&input));
+ assert_eq!(
+ crate::Hasher::new()
+ .update_mmap(tempfile.path())?
+ .finalize(),
+ crate::hash(&input),
+ );
Ok(())
}
@@ -792,8 +798,11 @@ fn test_mmap_rayon() -> Result<(), std::io::Error> {
let mut tempfile = tempfile::NamedTempFile::new()?;
tempfile.write_all(&input)?;
tempfile.flush()?;
- let mut hasher = crate::Hasher::new();
- hasher.update_mmap_rayon(tempfile.path())?;
- assert_eq!(hasher.finalize(), crate::hash(&input));
+ assert_eq!(
+ crate::Hasher::new()
+ .update_mmap_rayon(tempfile.path())?
+ .finalize(),
+ crate::hash(&input),
+ );
Ok(())
}