From 9837699b79feec49939c4805adcad315fb20a5f3 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 30 Jan 2023 14:25:30 +0100 Subject: [PATCH] Introduce new let...else syntax (#936) --- lychee-lib/src/helpers/path.rs | 23 ++++++++--------------- lychee-lib/src/types/input.rs | 5 ++--- lychee-lib/src/types/uri/github.rs | 5 ++--- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lychee-lib/src/helpers/path.rs b/lychee-lib/src/helpers/path.rs index b276616..7966ee8 100644 --- a/lychee-lib/src/helpers/path.rs +++ b/lychee-lib/src/helpers/path.rs @@ -44,9 +44,8 @@ pub(crate) fn resolve(src: &Path, dst: &Path, base: &Option) -> Result { // Find `dst` in the parent directory of `src` - let parent = match src.parent() { - Some(parent) => parent, - None => return Err(ErrorKind::FileNotFound(relative.to_path_buf())), + let Some(parent) = src.parent() else { + return Err(ErrorKind::FileNotFound(relative.to_path_buf())) }; parent.join(relative) } @@ -54,18 +53,12 @@ pub(crate) fn resolve(src: &Path, dst: &Path, base: &Option) -> Result path, - None => return Ok(None), - }; - let dir = match dirname(&base) { - Some(dir) => dir, - None => { - return Err(ErrorKind::InvalidBase( - base.display().to_string(), - "The given directory cannot be a base".to_string(), - )) - } + let Some(base) = get_base_dir(base) else { return Ok(None) }; + let Some(dir) = dirname(&base) else { + return Err(ErrorKind::InvalidBase( + base.display().to_string(), + "The given directory cannot be a base".to_string(), + )) }; join(dir.to_path_buf(), absolute) } diff --git a/lychee-lib/src/types/input.rs b/lychee-lib/src/types/input.rs index c64ff46..ddea47e 100644 --- a/lychee-lib/src/types/input.rs +++ b/lychee-lib/src/types/input.rs @@ -315,9 +315,8 @@ impl Input { /// Check if the given path was excluded from link checking fn is_excluded_path(&self, path: &PathBuf) -> bool { - let excluded_paths = match &self.excluded_paths { - Some(excluded) => excluded, - None => return false, + let Some(excluded_paths) = &self.excluded_paths else { + return false }; is_excluded_path(excluded_paths, path) } diff --git a/lychee-lib/src/types/uri/github.rs b/lychee-lib/src/types/uri/github.rs index a04f2c2..9f7ff13 100644 --- a/lychee-lib/src/types/uri/github.rs +++ b/lychee-lib/src/types/uri/github.rs @@ -64,9 +64,8 @@ impl GithubUri { debug_assert!(!uri.is_mail(), "Should only be called on a Website type!"); - let domain = match uri.domain() { - Some(domain) => domain, - None => return Err(ErrorKind::InvalidGithubUrl(uri.to_string())), + let Some(domain) = uri.domain() else { + return Err(ErrorKind::InvalidGithubUrl(uri.to_string())) }; if !matches!(