Introduce new let...else syntax (#936)

This commit is contained in:
Matthias Endler 2023-01-30 14:25:30 +01:00 committed by GitHub
parent 06b0f27b74
commit 9837699b79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 21 deletions

View file

@ -44,9 +44,8 @@ pub(crate) fn resolve(src: &Path, dst: &Path, base: &Option<Base>) -> Result<Opt
let resolved = match dst {
relative if dst.is_relative() => {
// 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<Base>) -> Result<Opt
// Absolute local links (leading slash) require the `base_url` to
// define the document root. Silently ignore the link in case the
// `base_url` is not defined.
let base = match get_base_dir(base) {
Some(path) => 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)
}

View file

@ -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)
}

View file

@ -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!(