Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed May 15, 2022
1 parent 7c2e783 commit 50fa257
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lychee-bin/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn parse_remaps(remaps: &[String]) -> Result<Remaps> {

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))
Expand Down
7 changes: 5 additions & 2 deletions lychee-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> {
match self.remaps {
Some(ref remaps) => remaps.remap(uri),
Expand Down
17 changes: 14 additions & 3 deletions lychee-lib/src/remap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> {
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()
}
Expand Down

0 comments on commit 50fa257

Please sign in to comment.