Change a few method signatures to accept impl Into<String>, instead of &str
Motivation
Currently, several methods like MessageDialog::set_title, MessageDialog::set_description or FileDialog::add_filter accept &str as one of the arguments - this is extremely inconvenient, as if you have a String from format! 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 Strings, so it'd make more sense to convert anything to a String in the methods themselves.
To tackle this question, we first need to know the difference between two traits.
ToString - converts the value to String without consuming it.
Into<String> - consumes the value while converting it to a String.
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 both Into<String> and ToString
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 asString
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