Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmd/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'a> AsRow<'a> for DiffLine {
}

impl DiffLine {
fn path_display(&self) -> Cow<str> {
fn path_display(&self) -> Cow<'_, str> {
match &self.diff {
Diff::Renamed { original, renamed } => Cow::Owned(format!(
"{} -> {}",
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions src/ocfl/bimap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -153,12 +147,12 @@ where
}

/// Returns an iterator that iterates over references to all path-id pairs
pub fn iter(&self) -> Iter<Rc<P>, Rc<HexDigest>> {
pub fn iter(&self) -> Iter<'_, Rc<P>, Rc<HexDigest>> {
self.path_to_id.iter()
}

/// Returns an iterator that iterates over id-paths pairs
pub fn iter_id_paths(&self) -> Iter<Rc<HexDigest>, HashSet<Rc<P>>> {
pub fn iter_id_paths(&self) -> Iter<'_, Rc<HexDigest>, HashSet<Rc<P>>> {
self.id_to_paths.iter()
}

Expand Down
9 changes: 4 additions & 5 deletions src/ocfl/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -641,7 +640,7 @@ impl Version {
}

/// Returns non-consuming iterator for the version's state
pub fn state_iter(&self) -> Iter<Rc<LogicalPath>, Rc<HexDigest>> {
pub fn state_iter(&self) -> Iter<'_, Rc<LogicalPath>, Rc<HexDigest>> {
self.state.iter()
}

Expand All @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
16 changes: 8 additions & 8 deletions src/ocfl/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
}
}

Expand Down Expand Up @@ -831,10 +831,10 @@ impl InventoryIter {
fn create_if_matches<P: AsRef<Path>>(&self, object_root: P) -> Option<Result<Inventory>> {
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
Expand Down Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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<Vec<Listing>> {
fn list(&self, path: &str, recursive: bool) -> Result<Vec<Listing<'_>>> {
let mut listings = Vec::new();
let root = self.storage_root.join(path);

Expand Down Expand Up @@ -1018,7 +1018,7 @@ fn is_object_root<P: AsRef<Path>>(path: P) -> Result<bool> {
.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);
}
Expand Down Expand Up @@ -1315,7 +1315,7 @@ fn find_files(dir: impl AsRef<Path>, prefix: &str) -> Result<Vec<OsString>> {
.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())
}

Expand All @@ -1328,7 +1328,7 @@ fn find_first_version_declaration(prefix: &str, dir: impl AsRef<Path>) -> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/ocfl/store/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> {
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;
Expand Down
6 changes: 3 additions & 3 deletions src/ocfl/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Listing>>;
fn list(&self, path: &str, recursive: bool) -> Result<Vec<Listing<'_>>>;

/// Returns the native path separator used by the store.
fn path_separator(&self) -> char;
Expand All @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/ocfl/store/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Listing>> {
fn list(&self, path: &str, recursive: bool) -> Result<Vec<Listing<'_>>> {
let prefix_len = if path.is_empty() || path.ends_with('/') {
path.len()
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/ocfl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>;
fn parts(&self) -> Split<'_, char>;

/// Returns the parent path of this path.
fn parent(&self) -> Self;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<char> {
fn parts(&self) -> Split<'_, char> {
self.0.split('/')
}

Expand Down Expand Up @@ -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<char> {
fn parts(&self) -> Split<'_, char> {
self.inner.parts()
}

Expand Down Expand Up @@ -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<char> {
fn parts(&self) -> Split<'_, char> {
self.inner.parts()
}

Expand Down
4 changes: 2 additions & 2 deletions src/ocfl/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ pub fn dir_is_empty(dir: impl AsRef<Path>) -> Result<bool> {
}

/// Changes `/` to `\` on Windows
pub fn convert_forwardslash_to_back(path: &str) -> Cow<str> {
pub fn convert_forwardslash_to_back(path: &str) -> Cow<'_, str> {
if BACKSLASH_SEPARATOR && path.contains('/') {
return Cow::Owned(path.replace('/', "\\"));
}
path.into()
}

/// Changes `\\` to `/` on Windows
pub fn convert_backslash_to_forward(path: &str) -> Cow<str> {
pub fn convert_backslash_to_forward(path: &str) -> Cow<'_, str> {
if BACKSLASH_SEPARATOR && path.contains('\\') {
return Cow::Owned(path.replace('\\', "/"));
}
Expand Down
8 changes: 4 additions & 4 deletions src/ocfl/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl<S: Storage> Validator<S> {
///
/// 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<IncrementalValidatorImpl<S>> {
pub fn validate_repo(&self, fixity_check: bool) -> Result<IncrementalValidatorImpl<'_, S>> {
let mut root_result = StorageValidationResult::new();
let files = self.storage.list("", false)?;

Expand Down Expand Up @@ -2051,7 +2051,7 @@ impl ParseValidationResult {
}

pub fn has_errors(&self) -> bool {
self.errors.borrow().len() > 0
!self.errors.borrow().is_empty()
}
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ocfl/validate/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl<'de> Deserialize<'de> for OptionWrapper<Inventory> {
)
}

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,
Expand Down
Loading