summaryrefslogtreecommitdiffstats
path: root/src/repository/repository.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-06-20 18:52:31 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-08-18 10:07:17 +0200
commita4c2d39a3bd552278a6d348312f919430e2c3323 (patch)
treeb219e4c0bb011eba965adbf2beece2b5f9a361c6 /src/repository/repository.rs
parent9fd0590b513644f5b5633b2600d907b6382bb5f0 (diff)
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 <mail@beyermatthias.de>
Diffstat (limited to 'src/repository/repository.rs')
-rw-r--r--src/repository/repository.rs20
1 files changed, 9 insertions, 11 deletions
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