Skip to content

Commit

Permalink
refactor(lib): Tweak TestHelper Parse method chain (#35)
Browse files Browse the repository at this point in the history
Whilst working on a previous commit, refactoring the implementation of
the top-level `test_gen` proc-macro function, I was reminded of a method
style which would allow the combinations of the `Option::map` and
`Option::unwrap_or_else` methods, into a single method call, with the
use of `Option::map_or_else`. This is only a minor commit, to implement
this improvement.
  • Loading branch information
DunnAnDusted authored Dec 14, 2022
1 parent 29423bf commit d9764bb
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ impl Parse for TestHelper {
let cases = cases
.is_empty()
.then(|| Error::new(cases.span(), "expected test cases"))
.map(Result::Err) // Wrapping the error with a `map` format more cleanly...
.unwrap_or_else(|| cases.parse_terminated(TestCase::parse))?;
.map_or_else(|| cases.parse_terminated(TestCase::parse), Result::Err)?;

let out = TestHelper {
static_attrs,
Expand Down

0 comments on commit d9764bb

Please sign in to comment.