Skip to content

Commit

Permalink
improve code with unwrap_or and expect for Option<>
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Jul 25, 2024
1 parent ee98c03 commit feb838a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/concourse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl Source {
}
// return unwrapped value with default false for ease of use
pub(crate) fn skip_check(&self) -> bool {
return match self.skip_check {
Some(skip_check) => skip_check,
None => false,
};
return self.skip_check.unwrap_or(false)
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl concourse_resource::Resource for GithubIssue {
_ = env_logger::try_init();

// validate and unwrap source
let source = match source {
Some(source) => source,
None => panic!("source is required for the Github Issue resource"),
};
let source = source.expect("source is required for the Github Issue resource");

// return immediately with two sized vector if check step skip requested (e.g. source for out/put+create)
if source.skip_check() {
Expand Down Expand Up @@ -115,15 +112,8 @@ impl concourse_resource::Resource for GithubIssue {
_ = env_logger::try_init();

// validate source and params
let source = match source {
Some(source) => source,
// note it would be bizarre if this was ever reached since it is already validated in check
None => panic!("source is required for the Github Issue resource"),
};
let params = match params {
Some(params) => params,
None => panic!("params is required for the Github Issue resource out/put step"),
};
let source = source.expect("source is required for the Github Issue resource");
let params = params.expect("params is required for the Github Issue resource out/put step");

// create longer lifetime bindings
let owner_binding = source.owner();
Expand Down

0 comments on commit feb838a

Please sign in to comment.