diff --git a/src/cmd/diff.rs b/src/cmd/diff.rs index 92a5507..5e7f2d0 100644 --- a/src/cmd/diff.rs +++ b/src/cmd/diff.rs @@ -60,7 +60,7 @@ impl LogCmd { } } - fn version_table(&self, args: GlobalArgs) -> TableView { + fn version_table(&self, args: GlobalArgs) -> TableView<'_> { let columns = vec![ Column::new(ColumnId::Version, "Version", Alignment::Right), Column::new(ColumnId::Author, "Author", Alignment::Left), @@ -243,7 +243,7 @@ impl<'a> AsRow<'a> for DiffLine { } impl DiffLine { - fn path_display(&self) -> Cow { + fn path_display(&self) -> Cow<'_, str> { match &self.diff { Diff::Renamed { original, renamed } => Cow::Owned(format!( "{} -> {}", diff --git a/src/cmd/list.rs b/src/cmd/list.rs index a0d4291..2374b19 100644 --- a/src/cmd/list.rs +++ b/src/cmd/list.rs @@ -232,7 +232,7 @@ impl ListCmd { Ok(()) } - fn object_table(&self, args: GlobalArgs) -> TableView { + fn object_table(&self, args: GlobalArgs) -> TableView<'_> { let mut columns = Vec::new(); if self.long { @@ -253,7 +253,7 @@ impl ListCmd { TableView::new(columns, self.separator(), self.header, !args.no_styles) } - fn object_content_table(&self, args: GlobalArgs) -> TableView { + fn object_content_table(&self, args: GlobalArgs) -> TableView<'_> { let mut columns = Vec::new(); if self.long { diff --git a/src/cmd/table.rs b/src/cmd/table.rs index a94a44f..7a9162b 100644 --- a/src/cmd/table.rs +++ b/src/cmd/table.rs @@ -146,7 +146,7 @@ impl Column { self.width = cmp::max(self.width, new_width); } - fn heading_cell(&self) -> TextCell { + fn heading_cell(&self) -> TextCell<'_> { let mut cell = TextCell::new(&self.heading); cell.style = &*style::UNDERLINE; cell diff --git a/src/ocfl/bimap.rs b/src/ocfl/bimap.rs index 592c51e..e652cd6 100644 --- a/src/ocfl/bimap.rs +++ b/src/ocfl/bimap.rs @@ -59,7 +59,7 @@ where let entry = self.id_to_paths.entry(id_ref); let id_ref = entry.key().clone(); - entry.or_insert_with(HashSet::new).insert(path_ref.clone()); + entry.or_default().insert(path_ref.clone()); self.path_to_id.insert(path_ref, id_ref); } @@ -72,10 +72,7 @@ where let id_ref = Rc::new(id); - let set = self - .id_to_paths - .entry(id_ref.clone()) - .or_insert_with(HashSet::new); + let set = self.id_to_paths.entry(id_ref.clone()).or_default(); for path in paths { let path_ref = Rc::new(path); @@ -90,10 +87,7 @@ where return; } - let set = self - .id_to_paths - .entry(id.clone()) - .or_insert_with(HashSet::new); + let set = self.id_to_paths.entry(id.clone()).or_default(); for path in paths { set.insert(path.clone()); @@ -153,12 +147,12 @@ where } /// Returns an iterator that iterates over references to all path-id pairs - pub fn iter(&self) -> Iter, Rc> { + pub fn iter(&self) -> Iter<'_, Rc

, Rc> { self.path_to_id.iter() } /// Returns an iterator that iterates over id-paths pairs - pub fn iter_id_paths(&self) -> Iter, HashSet>> { + pub fn iter_id_paths(&self) -> Iter<'_, Rc, HashSet>> { self.id_to_paths.iter() } diff --git a/src/ocfl/inventory.rs b/src/ocfl/inventory.rs index 0c1aecf..4c61cf4 100644 --- a/src/ocfl/inventory.rs +++ b/src/ocfl/inventory.rs @@ -2,7 +2,6 @@ use std::borrow::Cow; use std::collections::hash_map::Iter; use std::collections::{BTreeMap, HashMap, HashSet}; use std::convert::{TryFrom, TryInto}; -use std::mem; use std::rc::Rc; use std::str::FromStr; @@ -329,7 +328,7 @@ impl Inventory { if path.starts_with(&prefix) { matches .entry(digest.clone()) - .or_insert_with(HashSet::new) + .or_default() .insert(path.clone()); } } @@ -641,7 +640,7 @@ impl Version { } /// Returns non-consuming iterator for the version's state - pub fn state_iter(&self) -> Iter, Rc> { + pub fn state_iter(&self) -> Iter<'_, Rc, Rc> { self.state.iter() } @@ -660,7 +659,7 @@ impl Version { if self.logical_dirs.get().is_some() { self.logical_dirs = OnceCell::default(); } - mem::replace(&mut self.state, PathBiMap::new()) + std::mem::take(&mut self.state) } /// Returns a reference to the digest associated to a logical path, or None if the logical @@ -807,7 +806,7 @@ impl Version { None => { deletes .entry(left_digest.clone()) - .or_insert_with(Vec::new) + .or_default() .push(path.clone()); } Some(right_digest) => { diff --git a/src/ocfl/store/fs.rs b/src/ocfl/store/fs.rs index b8c81f3..4abd8e4 100644 --- a/src/ocfl/store/fs.rs +++ b/src/ocfl/store/fs.rs @@ -422,7 +422,7 @@ impl OcflStore for FsOcflStore { let old_namastes = find_files(&object_root, OBJECT_NAMASTE_FILE_PREFIX)?; write_object_namaste(&object_root, inventory.spec_version().unwrap())?; for old in old_namastes { - util::remove_file_ignore_not_found(&object_root.join(old))?; + util::remove_file_ignore_not_found(object_root.join(old))?; } } @@ -831,10 +831,10 @@ impl InventoryIter { fn create_if_matches>(&self, object_root: P) -> Option> { let inventory_path = paths::inventory_path(&object_root); - if self.id_matcher.is_some() { + if let Some(id_matcher) = &self.id_matcher { match self.extract_object_id(&inventory_path) { Some(Ok(object_id)) => { - if self.id_matcher.as_ref().unwrap().deref()(&object_id) { + if id_matcher.deref()(&object_id) { Some(parse_inventory(object_root, &self.root)) } else { None @@ -869,7 +869,7 @@ impl InventoryIter { e )))) } else { - match matches.get(0) { + match matches.first() { Some(id) => Some(Ok(id.to_string())), None => Some(Err(RocflError::General(format!( "Failed to locate object ID in inventory at {}", @@ -961,7 +961,7 @@ impl Storage for FsStorage { /// Lists the contents of the specified directory. If `recursive` is `true`, then all leaf-nodes /// are returned. If the directory does not exist, or is empty, then an empty vector is returned. /// The returned paths are all relative the directory that was listed. - fn list(&self, path: &str, recursive: bool) -> Result> { + fn list(&self, path: &str, recursive: bool) -> Result>> { let mut listings = Vec::new(); let root = self.storage_root.join(path); @@ -1018,7 +1018,7 @@ fn is_object_root>(path: P) -> Result { .file_name() .unwrap_or_default() .to_str() - .map_or(false, |name| name.starts_with(OBJECT_NAMASTE_FILE_PREFIX)) + .is_some_and(|name| name.starts_with(OBJECT_NAMASTE_FILE_PREFIX)) { return Ok(true); } @@ -1315,7 +1315,7 @@ fn find_files(dir: impl AsRef, prefix: &str) -> Result> { .flatten() .map(|entry| entry.file_name()) .filter(|name| name.len() > prefix.len()) - .filter(|name| name.to_str().map_or(false, |name| name.starts_with(prefix))) + .filter(|name| name.to_str().is_some_and(|name| name.starts_with(prefix))) .collect()) } @@ -1328,7 +1328,7 @@ fn find_first_version_declaration(prefix: &str, dir: impl AsRef) -> Result && entry .file_name() .to_str() - .map_or(false, |name| name.starts_with(prefix)) + .is_some_and(|name| name.starts_with(prefix)) { let version = entry.file_name().to_str().unwrap()[prefix.len()..].to_string(); return Ok(version); diff --git a/src/ocfl/store/layout.rs b/src/ocfl/store/layout.rs index 3fcfc3e..a052665 100644 --- a/src/ocfl/store/layout.rs +++ b/src/ocfl/store/layout.rs @@ -658,11 +658,11 @@ fn to_tuples(value: &str, tuple_size: usize, number_of_tuples: usize) -> String /// /// This method assumes that ALL unicode characters have been percent encoded. It is NOT SAFE /// to use on strings that contain unicode. -fn lower_percent_escape(original: &str) -> Cow { +fn lower_percent_escape(original: &str) -> Cow<'_, str> { if let Some(first) = original.find('%') { let start = first + 1; let mut out = Vec::with_capacity(original.len()); - out.extend_from_slice(original[..start].as_bytes()); + out.extend_from_slice(&original.as_bytes()[..start]); let search = original[start..].bytes(); let mut count = 2; diff --git a/src/ocfl/store/mod.rs b/src/ocfl/store/mod.rs index 4a8cc0f..310ca1f 100644 --- a/src/ocfl/store/mod.rs +++ b/src/ocfl/store/mod.rs @@ -190,7 +190,7 @@ pub trait Storage { /// Lists the contents of the specified directory. If `recursive` is `true`, then all leaf-nodes /// are returned. If the directory does not exist, or is empty, then an empty vector is returned. /// The returned paths are all relative the directory that was listed. - fn list(&self, path: &str, recursive: bool) -> Result>; + fn list(&self, path: &str, recursive: bool) -> Result>>; /// Returns the native path separator used by the store. fn path_separator(&self) -> char; @@ -208,11 +208,11 @@ pub enum Listing<'a> { } impl<'a> Listing<'a> { - pub fn file(path: &str) -> Listing { + pub fn file(path: &str) -> Listing<'_> { Listing::File(Cow::Borrowed(path)) } - pub fn dir(path: &str) -> Listing { + pub fn dir(path: &str) -> Listing<'_> { Listing::Directory(Cow::Borrowed(path)) } pub fn file_owned(path: String) -> Listing<'a> { diff --git a/src/ocfl/store/s3.rs b/src/ocfl/store/s3.rs index 414c182..87bb98e 100644 --- a/src/ocfl/store/s3.rs +++ b/src/ocfl/store/s3.rs @@ -1181,7 +1181,7 @@ impl Storage for S3Storage { /// Lists the contents of the specified directory. If `recursive` is `true`, then all leaf-nodes /// are returned. If the directory does not exist, or is empty, then an empty vector is returned. /// The returned paths are all relative the directory that was listed. - fn list(&self, path: &str, recursive: bool) -> Result> { + fn list(&self, path: &str, recursive: bool) -> Result>> { let prefix_len = if path.is_empty() || path.ends_with('/') { path.len() } else { diff --git a/src/ocfl/types.rs b/src/ocfl/types.rs index f947106..590772b 100644 --- a/src/ocfl/types.rs +++ b/src/ocfl/types.rs @@ -91,7 +91,7 @@ pub(crate) struct Namaste { pub trait InventoryPath { /// Returns an iterable containing each segment of the path split on the `/` separator - fn parts(&self) -> Split; + fn parts(&self) -> Split<'_, char>; /// Returns the parent path of this path. fn parent(&self) -> Self; @@ -300,7 +300,7 @@ impl VersionNum { _ => u32::pow(10, self.width - 1) - 1, }; - if self.number + 1 > max as u32 { + if self.number + 1 > max { return Err(RocflError::IllegalState(format!( "Version cannot be greater than {}", max @@ -576,7 +576,7 @@ impl Namaste { impl InventoryPath for InventoryPathInner { /// Returns an iterable containing each segment of the path split on the `/` separator - fn parts(&self) -> Split { + fn parts(&self) -> Split<'_, char> { self.0.split('/') } @@ -634,7 +634,7 @@ impl InventoryPath for InventoryPathInner { impl InventoryPath for LogicalPath { /// Returns an iterable containing each segment of the path split on the `/` separator - fn parts(&self) -> Split { + fn parts(&self) -> Split<'_, char> { self.inner.parts() } @@ -686,7 +686,7 @@ impl InventoryPath for LogicalPath { impl InventoryPath for ContentPath { /// Returns an iterable containing each segment of the path split on the `/` separator - fn parts(&self) -> Split { + fn parts(&self) -> Split<'_, char> { self.inner.parts() } diff --git a/src/ocfl/util.rs b/src/ocfl/util.rs index 73805aa..cc195f6 100644 --- a/src/ocfl/util.rs +++ b/src/ocfl/util.rs @@ -51,7 +51,7 @@ pub fn dir_is_empty(dir: impl AsRef) -> Result { } /// Changes `/` to `\` on Windows -pub fn convert_forwardslash_to_back(path: &str) -> Cow { +pub fn convert_forwardslash_to_back(path: &str) -> Cow<'_, str> { if BACKSLASH_SEPARATOR && path.contains('/') { return Cow::Owned(path.replace('/', "\\")); } @@ -59,7 +59,7 @@ pub fn convert_forwardslash_to_back(path: &str) -> Cow { } /// Changes `\\` to `/` on Windows -pub fn convert_backslash_to_forward(path: &str) -> Cow { +pub fn convert_backslash_to_forward(path: &str) -> Cow<'_, str> { if BACKSLASH_SEPARATOR && path.contains('\\') { return Cow::Owned(path.replace('\\', "/")); } diff --git a/src/ocfl/validate/mod.rs b/src/ocfl/validate/mod.rs index 3fd5212..6831743 100644 --- a/src/ocfl/validate/mod.rs +++ b/src/ocfl/validate/mod.rs @@ -660,7 +660,7 @@ impl Validator { /// /// The storage root is validated immediately, and an incremental validator is returned that /// is used to lazily validate the rest of the repository. - pub fn validate_repo(&self, fixity_check: bool) -> Result> { + pub fn validate_repo(&self, fixity_check: bool) -> Result> { let mut root_result = StorageValidationResult::new(); let files = self.storage.list("", false)?; @@ -2051,7 +2051,7 @@ impl ParseValidationResult { } pub fn has_errors(&self) -> bool { - self.errors.borrow().len() > 0 + !self.errors.borrow().is_empty() } } @@ -2070,13 +2070,13 @@ impl ContentPaths { fn add_path(&mut self, path: ContentPath) { if let ContentPathVersion::VersionNum(num) = path.version { - self.path_map.entry(num).or_insert_with(Vec::new).push(path); + self.path_map.entry(num).or_default().push(path); } } /// Iterates over all of the content files that _should_ appear in the manifest of an inventory /// at the specified `version_num`. Paths from later versions are not included. - fn iter(&self, version_num: VersionNum) -> ContentPathsIter { + fn iter(&self, version_num: VersionNum) -> ContentPathsIter<'_> { ContentPathsIter { current_version: version_num, current_iter: self diff --git a/src/ocfl/validate/serde.rs b/src/ocfl/validate/serde.rs index 86b2e11..dbc8012 100644 --- a/src/ocfl/validate/serde.rs +++ b/src/ocfl/validate/serde.rs @@ -419,7 +419,7 @@ impl<'de> Deserialize<'de> for OptionWrapper { ) } - if let Some(highest_version) = versions.nums.iter().rev().next() { + if let Some(highest_version) = versions.nums.iter().next_back() { if head != highest_version { self.result.error( ErrorCode::E040, diff --git a/tests/fs-tests.rs b/tests/fs-tests.rs index 8ddf0c0..6b29d99 100644 --- a/tests/fs-tests.rs +++ b/tests/fs-tests.rs @@ -1368,7 +1368,7 @@ fn copy_should_partially_succeed_when_multiple_src_and_some_fail() { match result { Err(RocflError::CopyMoveError(e)) => { assert_eq!(1, e.0.len()); - assert!(e.0.get(0).unwrap().contains("bogus: Does not exist")); + assert!(e.0.first().unwrap().contains("bogus: Does not exist")); } _ => panic!("Expected copy to return an error"), } @@ -2200,7 +2200,7 @@ fn internal_copy_should_continue_on_partial_success() -> Result<()> { assert_eq!(1, e.0.len()); assert!(e .0 - .get(0) + .first() .unwrap() .contains("does not contain any files at bogus.txt")); } @@ -2225,8 +2225,8 @@ fn internal_copy_should_continue_on_partial_success() -> Result<()> { "4ccdbf78d368aed12d806efaf67fbce3300bca8e62a6f32716af2f447de1821e", ); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_some()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_some()); + assert!(staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(staged_obj.state.contains_key(&lpath("a/file5.txt"))); validate_repo(&repo); Ok(()) @@ -2751,7 +2751,7 @@ fn move_should_partially_succeed_when_multiple_src_and_some_fail() { match result { Err(RocflError::CopyMoveError(e)) => { assert_eq!(1, e.0.len()); - assert!(e.0.get(0).unwrap().contains("bogus: Does not exist")); + assert!(e.0.first().unwrap().contains("bogus: Does not exist")); } _ => panic!("Expected copy to return an error"), } @@ -2850,7 +2850,7 @@ fn internal_move_single_existing_file() -> Result<()> { "7d9fe7396f8f5f9862bfbfff4d98877bf36cf4a44447078c8d887dcc2dab0497", ); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); commit(object_id, &repo); @@ -2865,7 +2865,7 @@ fn internal_move_single_existing_file() -> Result<()> { "7d9fe7396f8f5f9862bfbfff4d98877bf36cf4a44447078c8d887dcc2dab0497", ); - assert!(committed_obj.state.get(&lpath("a/file1.txt")).is_none()); + assert!(!committed_obj.state.contains_key(&lpath("a/file1.txt"))); validate_repo(&repo); Ok(()) @@ -2908,9 +2908,9 @@ fn internal_move_multiple_existing_file() -> Result<()> { "b47592b10bc3e5c8ca8703d0862df10a6e409f43478804f93a08dd1844ae81b6", ); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/b/file2.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/b/file2.txt"))); commit(object_id, &repo); @@ -2946,9 +2946,9 @@ fn internal_move_multiple_existing_file() -> Result<()> { "b47592b10bc3e5c8ca8703d0862df10a6e409f43478804f93a08dd1844ae81b6", ); - assert!(committed_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(committed_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(committed_obj.state.get(&lpath("a/b/file2.txt")).is_none()); + assert!(!committed_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!committed_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!committed_obj.state.contains_key(&lpath("a/b/file2.txt"))); validate_repo(&repo); Ok(()) @@ -2976,7 +2976,7 @@ fn internal_move_should_continue_on_partial_success() -> Result<()> { assert_eq!(1, e.0.len()); assert!(e .0 - .get(0) + .first() .unwrap() .contains("does not contain any files at bogus.txt")); } @@ -3001,8 +3001,8 @@ fn internal_move_should_continue_on_partial_success() -> Result<()> { "4ccdbf78d368aed12d806efaf67fbce3300bca8e62a6f32716af2f447de1821e", ); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); validate_repo(&repo); Ok(()) @@ -3040,7 +3040,7 @@ fn internal_move_files_added_in_staged_version() { "b37d2cbfd875891e9ed073fcbe61f35a990bee8eecbdd07f9efc51339d5ffd66", ); - assert!(staged_obj.state.get(&lpath("just in.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("just in.txt"))); commit(object_id, &repo); @@ -3132,18 +3132,18 @@ fn remove_existing_file() -> Result<()> { let staged_obj = repo.get_staged_object(object_id)?; assert_eq!(6, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); commit(object_id, &repo); let committed_obj = repo.get_object(object_id, VersionRef::Head)?; assert_eq!(6, committed_obj.state.len()); - assert!(committed_obj.state.get(&lpath("a/file5.txt")).is_none()); + assert!(!committed_obj.state.contains_key(&lpath("a/file5.txt"))); let previous_version = repo.get_object(object_id, 4.try_into()?)?; - assert!(previous_version.state.get(&lpath("a/file5.txt")).is_some()); + assert!(previous_version.state.contains_key(&lpath("a/file5.txt"))); validate_repo(&repo); Ok(()) @@ -3165,27 +3165,25 @@ fn remove_multiple_existing_files() -> Result<()> { let staged_obj = repo.get_staged_object(object_id)?; assert_eq!(5, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("something/new.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("something/new.txt"))); commit(object_id, &repo); let committed_obj = repo.get_object(object_id, VersionRef::Head)?; assert_eq!(5, committed_obj.state.len()); - assert!(committed_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(committed_obj + assert!(!committed_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!committed_obj .state - .get(&lpath("something/new.txt")) - .is_none()); + .contains_key(&lpath("something/new.txt"))); let previous_version = repo.get_object(object_id, 4.try_into()?)?; - assert!(previous_version.state.get(&lpath("a/file5.txt")).is_some()); + assert!(previous_version.state.contains_key(&lpath("a/file5.txt"))); assert!(previous_version .state - .get(&lpath("something/new.txt")) - .is_some()); + .contains_key(&lpath("something/new.txt"))); validate_repo(&repo); Ok(()) @@ -3207,22 +3205,22 @@ fn remove_globs() -> Result<()> { let staged_obj = repo.get_staged_object(object_id)?; assert_eq!(5, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/f/file6.txt")).is_some()); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(staged_obj.state.contains_key(&lpath("a/f/file6.txt"))); commit(object_id, &repo); let committed_obj = repo.get_object(object_id, VersionRef::Head)?; assert_eq!(5, committed_obj.state.len()); - assert!(committed_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(committed_obj.state.get(&lpath("a/file1.txt")).is_none()); + assert!(!committed_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!committed_obj.state.contains_key(&lpath("a/file1.txt"))); let previous_version = repo.get_object(object_id, 4.try_into()?)?; - assert!(previous_version.state.get(&lpath("a/file5.txt")).is_some()); - assert!(previous_version.state.get(&lpath("a/file1.txt")).is_some()); + assert!(previous_version.state.contains_key(&lpath("a/file5.txt"))); + assert!(previous_version.state.contains_key(&lpath("a/file1.txt"))); validate_repo(&repo); Ok(()) @@ -3244,14 +3242,14 @@ fn remove_recursive() -> Result<()> { let staged_obj = repo.get_staged_object(object_id)?; assert_eq!(1, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("file3.txt")).is_some()); + assert!(staged_obj.state.contains_key(&lpath("file3.txt"))); commit(object_id, &repo); let committed_obj = repo.get_object(object_id, VersionRef::Head)?; assert_eq!(1, committed_obj.state.len()); - assert!(committed_obj.state.get(&lpath("file3.txt")).is_some()); + assert!(committed_obj.state.contains_key(&lpath("file3.txt"))); validate_repo(&repo); Ok(()) @@ -3273,7 +3271,7 @@ fn remove_files_that_do_not_exist_should_do_nothing() -> Result<()> { let staged_obj = repo.get_staged_object(object_id)?; assert_eq!(6, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("file3.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("file3.txt"))); validate_repo(&repo); Ok(()) @@ -3323,8 +3321,8 @@ fn reset_newly_added_files() -> Result<()> { assert_eq!(8, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("new.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("new2.txt")).is_some()); + assert!(!staged_obj.state.contains_key(&lpath("new.txt"))); + assert!(staged_obj.state.contains_key(&lpath("new2.txt"))); commit(object_id, &repo); @@ -3333,7 +3331,7 @@ fn reset_newly_added_files() -> Result<()> { assert_eq!(8, obj.state.len()); - assert!(obj.state.get(&lpath("new.txt")).is_none()); + assert!(!obj.state.contains_key(&lpath("new.txt"))); assert!(!object_root .join("v5") .join("content") @@ -3400,8 +3398,8 @@ fn reset_copied_file() -> Result<()> { assert_eq!(8, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("new.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("new (copy).txt")).is_some()); + assert!(!staged_obj.state.contains_key(&lpath("new.txt"))); + assert!(staged_obj.state.contains_key(&lpath("new (copy).txt"))); commit(object_id, &repo); @@ -3410,7 +3408,7 @@ fn reset_copied_file() -> Result<()> { assert_eq!(8, obj.state.len()); - assert!(obj.state.get(&lpath("new.txt")).is_none()); + assert!(!obj.state.contains_key(&lpath("new.txt"))); assert_file_details( obj.state.get(&lpath("new (copy).txt")).unwrap(), @@ -3522,10 +3520,10 @@ fn reset_removed_file() -> Result<()> { assert_eq!(3, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/b/file2.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/f/file6.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/b/file2.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/f/file6.txt"))); repo.reset(object_id, &["a/f"], true)?; @@ -3533,8 +3531,8 @@ fn reset_removed_file() -> Result<()> { assert_eq!(4, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); let object_root = PathBuf::from(repo.get_object(object_id, VersionRef::Head)?.object_root); @@ -3551,8 +3549,8 @@ fn reset_removed_file() -> Result<()> { assert_eq!(4, obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); assert_file_details( obj.state.get(&lpath("a/f/file6.txt")).unwrap(), @@ -3609,16 +3607,15 @@ fn reset_complex_changes_without_conflict() -> Result<()> { assert_eq!(4, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/b/file2.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/f/file6.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/b/file2.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/f/file6.txt"))); - assert!(staged_obj.state.get(&lpath("a/b")).is_some()); + assert!(staged_obj.state.contains_key(&lpath("a/b"))); assert!(staged_obj .state - .get(&lpath("a/file1.txt/file3.txt")) - .is_some()); + .contains_key(&lpath("a/file1.txt/file3.txt"))); repo.reset(object_id, &["*"], true)?; @@ -3626,11 +3623,10 @@ fn reset_complex_changes_without_conflict() -> Result<()> { assert_eq!(7, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/b")).is_none()); - assert!(staged_obj + assert!(!staged_obj.state.contains_key(&lpath("a/b"))); + assert!(!staged_obj .state - .get(&lpath("a/file1.txt/file3.txt")) - .is_none()); + .contains_key(&lpath("a/file1.txt/file3.txt"))); validate_repo(&repo); Ok(()) @@ -3662,16 +3658,15 @@ fn fail_reset_when_conflicted() { assert_eq!(4, staged_obj.state.len()); - assert!(staged_obj.state.get(&lpath("a/file1.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/file5.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/b/file2.txt")).is_none()); - assert!(staged_obj.state.get(&lpath("a/f/file6.txt")).is_none()); + assert!(!staged_obj.state.contains_key(&lpath("a/file1.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/file5.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/b/file2.txt"))); + assert!(!staged_obj.state.contains_key(&lpath("a/f/file6.txt"))); - assert!(staged_obj.state.get(&lpath("a/b")).is_some()); + assert!(staged_obj.state.contains_key(&lpath("a/b"))); assert!(staged_obj .state - .get(&lpath("a/file1.txt/file3.txt")) - .is_some()); + .contains_key(&lpath("a/file1.txt/file3.txt"))); repo.reset(object_id, &["a/file1.txt"], false).unwrap(); } @@ -4902,7 +4897,7 @@ fn assert_staged_obj_not_exists(repo: &OcflRepo, object_id: &str) { } fn assert_file_not_exists(obj: &ObjectVersion, logical_path: &str, content_path: &str) { - assert!(obj.state.get(&lpath(logical_path)).is_none()); + assert!(!obj.state.contains_key(&lpath(logical_path))); assert!(!Path::new(&obj.object_root).join(content_path).exists()); } diff --git a/tests/validate-tests.rs b/tests/validate-tests.rs index 0523f79..f94ca22 100644 --- a/tests/validate-tests.rs +++ b/tests/validate-tests.rs @@ -1384,7 +1384,7 @@ fn validate_object_does_not_exist() { #[test] fn validate_valid_repo() { - let repo = new_repo(&repo_test_path("valid")); + let repo = new_repo(repo_test_path("valid")); let mut validator = repo.validate_repo(true).unwrap(); no_errors_storage(validator.storage_root_result()); @@ -1402,7 +1402,7 @@ fn validate_valid_repo() { #[test] fn validate_invalid_repo() { - let repo = new_repo(&repo_test_path("invalid")); + let repo = new_repo(repo_test_path("invalid")); let mut validator = repo.validate_repo(true).unwrap(); has_errors_storage( @@ -1476,7 +1476,7 @@ fn validate_invalid_repo() { #[test] fn multiple_root_version_declarations() { - let repo = new_repo(&repo_test_path("multiple-root-decls")); + let repo = new_repo(repo_test_path("multiple-root-decls")); let mut validator = repo.validate_repo(true).unwrap(); has_errors_storage(