From a4c2d39a3bd552278a6d348312f919430e2c3323 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Jun 2021 18:52:31 +0200 Subject: Refactor getting patches and ignoring NotFound error Use `Result::or_else()` and match for error kinds instead of matching the whole `Result`, for less nesting. Signed-off-by: Matthias Beyer --- src/repository/repository.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/repository') diff --git a/src/repository/repository.rs b/src/repository/repository.rs index cca3842..8dee4cb 100644 --- a/src/repository/repository.rs +++ b/src/repository/repository.rs @@ -131,17 +131,15 @@ impl Repository { let path_relative_to_root = path.strip_prefix(root)?; // get the patches that are in the `config` object after the merge - let patches = match config.get_array("patches") { - Ok(v) => { - trace!("Patches after merging: {:?}", v); - v - }, - - // if there was none, we simply use an empty array - // This is cheap because Vec::with_capacity(0) does not allocate - Err(config::ConfigError::NotFound(_)) => Vec::with_capacity(0), - Err(e) => return Err(e).map_err(Error::from), - } + let patches = config + .get_array("patches") + .or_else(|e| match e { + + // if there was none, we simply use an empty array + // This is cheap because Vec::with_capacity(0) does not allocate + config::ConfigError::NotFound(_) => Ok(Vec::with_capacity(0)), + other => Err(other), + })? .into_iter() // Map all `Value`s to String and then join them on the path that is relative to -- cgit v1.2.3