PolyMeilex / rfd

Rusty File Dialog
MIT License
526 stars 60 forks source link

Change a few method signatures #117

Closed somedevfox closed 1 year ago

somedevfox commented 1 year ago

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 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.

Why Into<String> and not ToString?

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

PolyMeilex commented 1 year ago

Thanks!

somedevfox commented 1 year ago

<3