Reduced the lifetime from 'static to 'a for the on_change function of NumberInput#417
Merged
Merged
Conversation
genusistimelord
previously approved these changes
Mar 28, 2026
genusistimelord
left a comment
Collaborator
There was a problem hiding this comment.
looks good I think something in the older way we use to do things needed static but if its no longer needed I think this change is fine. Will just need to run the Example later to make sure its all functioning
…ssed to NumberInput.
Contributor
Author
|
I fixed the check failure by running cargo fmt (which added a comma to a line) then squashed the changes into 1 commit. |
genusistimelord
approved these changes
Mar 28, 2026
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.
First the lifetime didn't need to be 'static.
However my main reason for this is I was using the slider widget multiple times on a page so I created a structure that wrapped the slider to do all the common code between all the slider instances. This means that the on_change function I was passing in is already a Box<dyn Fn(u32) -> Message> with a lifetime tied to the structure, NOT static. So when I was trying to switch from using a slider to the number_input the compiler won't let me because of lifetimes.
This is my structure:
And the code to generate the control in the UI is:
However this failed because &self.on_change needed to have a 'static lifetime. By updating iced_aw's NumberInput so that on_change argument now has a lifetime of 'a instead of 'static the compiler is happy and I'm not constrained by the on_change function.