Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reduce repeated code in state machine #10

Merged
merged 1 commit into from
Mar 6, 2020

Conversation

nastevens
Copy link
Collaborator

This replaces repeated boilerplate code around handling taking/putting the state with a wrapper type. This wrapper type moves the state machine itself into a closure, allowing nice things like using ? to return errors and other early returns. It also makes simple an "Errored" state for the state machine so that calling the state machine after it's already returned an error is no longer a panic.

Other than adding early returns where appropriate, I did not change state machine behavior in this commit. Unfortunately it doesn't look like Github diff is aligning very well, but something to keep in mind while reviewing.

This replaces repeated boilerplate code around handling taking/putting
the state with a wrapper type. This wrapper type moves the state machine
itself into a closure, allowing nice things like using ? to return
errors and other early returns. It also makes simple an "Errored" state
for the state machine so that calling the state machine after it's
already returned an error is no longer a panic.

Signed-off-by: Nick Stevens <[email protected]>
@codecov
Copy link

codecov bot commented Mar 4, 2020

Codecov Report

Merging #10 into master will increase coverage by 0.57%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #10      +/-   ##
==========================================
+ Coverage   81.96%   82.53%   +0.57%     
==========================================
  Files           5        6       +1     
  Lines         793      796       +3     
==========================================
+ Hits          650      657       +7     
+ Misses        143      139       -4     
Impacted Files Coverage Δ
src/state.rs 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9866611...022dbc0. Read the comment docs.

@nastevens nastevens merged commit 27ef1e5 into master Mar 6, 2020
@nastevens nastevens deleted the wrap-state-machine-in-closure branch March 6, 2020 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants