Add a configurable drop behavior for Spinner #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds an
on_drop
method to Spinner, the method is a"Builder method" (called on a Spinner taking ownership and returns a new
Spinner instance). The existing Spinner API therefore continue to work
as they did before with no changes to methods or their parameters.
By default, i.e. when
on_drop
is not used to set the default behaviorof a Spinner, its behavior remains the same as prior to this commit.
When
on_drop
is called on a Spinner, a new Spinner instance isreturned. If this instance is dropped without any of its
stop*
methodshaving been called, then the
StopBehavior
set in theon_drop
call istriggered.
This change allows the following simple construction:
If
do_something_fallible()
returns aResult::Ok
the Spinner isstopped with the "success" message. Conversely, if
do_something_fallible()
returns aResult::Err
, the Spinner isstopped with the "Failed!" message when it is dropped.
All feedback is very welcome!