From 50fa257cd5799071d06dac4794333ff8bef02675 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 15 May 2022 15:04:41 +0200 Subject: [PATCH] lint --- lychee-bin/src/parse.rs | 2 +- lychee-lib/src/client.rs | 7 +++++-- lychee-lib/src/remap.rs | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lychee-bin/src/parse.rs b/lychee-bin/src/parse.rs index aed6cd3d2b..bcda24f0c8 100644 --- a/lychee-bin/src/parse.rs +++ b/lychee-bin/src/parse.rs @@ -58,7 +58,7 @@ pub(crate) fn parse_remaps(remaps: &[String]) -> Result { let pattern = Regex::new(params[0])?; let url = Url::try_from(params[1])?; - parsed.push((pattern, url)) + parsed.push((pattern, url)); } Ok(Remaps::new(parsed)) diff --git a/lychee-lib/src/client.rs b/lychee-lib/src/client.rs index ca0d3c40f4..747d1a53a6 100644 --- a/lychee-lib/src/client.rs +++ b/lychee-lib/src/client.rs @@ -407,11 +407,14 @@ impl Client { } }; - Ok(Response::new(uri.to_owned(), status, source)) + Ok(Response::new(uri.clone(), status, source)) } /// Remap URI using the client-defined remap patterns - #[must_use] + /// + /// # Errors + /// + /// Returns an error if the remapping value is not a URI pub fn remap(&self, uri: Uri) -> Result { match self.remaps { Some(ref remaps) => remaps.remap(uri), diff --git a/lychee-lib/src/remap.rs b/lychee-lib/src/remap.rs index f6baa9cb0c..71756c4c84 100644 --- a/lychee-lib/src/remap.rs +++ b/lychee-lib/src/remap.rs @@ -21,23 +21,34 @@ pub struct Remaps(Vec<(Regex, Url)>); impl Remaps { /// Create a new remapper + #[must_use] pub fn new(patterns: Vec<(Regex, Url)>) -> Self { Self(patterns) } /// Remap URI using the client-defined remap patterns - #[must_use] + /// + /// # Errors + /// + /// Returns an error if the remapping value is not a URI pub fn remap(&self, uri: Uri) -> Result { let mut uri = uri; - for (pattern, new_url) in &self.0 { + for (pattern, new_uri) in &self.0 { if pattern.is_match(uri.as_str()) { - uri = Uri::try_from(new_url.to_owned())? + uri = Uri::try_from(new_uri.clone())?; } } Ok(uri) } + /// Returns `true` if there are no remappings defined. + #[must_use] + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + /// Get the number of defined remap rules + #[must_use] pub fn len(&self) -> usize { self.0.len() }