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.
Summary
Change a few method signatures to accept
impl Into<String>
, instead of&str
Motivation
Currently, several methods like
MessageDialog::set_title
,MessageDialog::set_description
orFileDialog::add_filter
accept&str
as one of the arguments - this is extremely inconvenient, as if you have aString
fromformat!
macro, one has to convert it to&str
and sometimes it may not be possible, due to the borrow checker.And internally - titles, descriptions, extensions, etc. are stored as
String
s, so it'd make more sense to convert anything to aString
in the methods themselves.Why
Into<String>
and notToString
?To tackle this question, we first need to know the difference between two traits.
ToString
- converts the value toString
without consuming it.Into<String>
- consumes the value while converting it to aString
.All methods in this PR use the arguments to show data in message boxes - therefore it's most unlikely for that data to be used after the message box is shown.
If one really needs to use the argument after a method from
rfd
, one can clone or copy the value.Compatibility with existing codebases
This PR doesn't require any overhaul for the users of the library, as
&str
implements bothInto<String>
andToString