Add a configurable drop behavior for Spinner#31
Open
rustn00b wants to merge 1 commit intoFGRibreau:masterfrom
Open
Add a configurable drop behavior for Spinner#31rustn00b wants to merge 1 commit intoFGRibreau:masterfrom
rustn00b wants to merge 1 commit intoFGRibreau:masterfrom
Conversation
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 behavior
of a Spinner, its behavior remains the same as prior to this commit.
When `on_drop` is called on a Spinner, a new Spinner instance is
returned. If this instance is dropped without any of its `stop*` methods
having been called, then the `StopBehavior` set in the `on_drop` call is
triggered.
This change allows the following simple construction:
```
{
let sp = Spinner::new(...).on_drop(StopBehavior::Message("Failed!");
do_something_fallible()?;
sp.stop_with_message("Yay, it worked);
}
```
If `do_something_fallible()` returns a `Result::Ok` the Spinner is
stopped with the "success" message. Conversely, if
`do_something_fallible()` returns a `Result::Err`, the Spinner is
stopped with the "Failed!" message when it is dropped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_dropmethod 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_dropis not used to set the default behaviorof a Spinner, its behavior remains the same as prior to this commit.
When
on_dropis called on a Spinner, a new Spinner instance isreturned. If this instance is dropped without any of its
stop*methodshaving been called, then the
StopBehaviorset in theon_dropcall istriggered.
This change allows the following simple construction:
If
do_something_fallible()returns aResult::Okthe 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!