Replace impl Into<String> with impl ToString#302
Conversation
This is something I ran into today. Types that implement `std::fmt::Display` cannot be passed to functions that take `impl Into<String>`. You have to call `display_thing.to_string()`. Its a small thing but would be fixed by instead taking `impl ToString`. Afaik `impl ToString` is a superset of `impl Into<String>`, unless users manually implement `Into<String> for T` (or `From<T> for String`) for their own types. However I think its more common to implement `Display` as that works with `println` and friends. The main difference is that `Display::fmt` can return errors but thats also quite rare in my experience. I did some testing in a [playground] and seems to work. [playground]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1111e071f6ae416ae2688d58d2e9b575
|
Thanks for the PR! A common use case is The ergonomic win may outweigh this, but I think we should create a micro-benchmark for the |
Ah yeah thats true. I didn't consider that. Would you add a benchmark here https://github.com/emilk/egui/blob/master/egui_demo_lib/benches/benchmark.rs? |
|
Yeah! I think it would be good to bench both There is also a possibility that, in a separate PR, I can remove the need for a |
This is to help evaluate the impact of #302
|
In my benchmark the |
|
Awesome! I looked into the clippy warnings and most of them are along the lines of Supporting that lint would require changing all the callsites to use @emilk What do you think about this? Should I add |
|
Yeah, mute it. The point of this PR is an ergonomic win, so forcing people to write |
* drag and zoom support for plots * update doctest * use impl ToString * revert back to Into<String> until #302 is solved * Apply suggestions from code review Co-authored-by: ilya sheprut <optitel223@gmail.com> * use persistence feature for PlotMemory * rename shift -> translate * remove automatic bounds * removed unused methods * Into<String> -> ToString * Apply suggestions from code review Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> * avoid potential invalid bounds bug * use new is_valid method * improve auto bounds behavior as suggested * use NOTHING to initialize min_auto_bounds Co-authored-by: ilya sheprut <optitel223@gmail.com> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* drag and zoom support for plots * update doctest * use impl ToString * revert back to Into<String> until #302 is solved * Apply suggestions from code review Co-authored-by: ilya sheprut <optitel223@gmail.com> * use persistence feature for PlotMemory * * split plot into multiple files * add curve from function * move more functionality into ScreenTransform struct * changes from code review in base branch * let user specify a range for generated functions * rename file * minor changes * improve generator functionality * improve callback and add parametric callback * minor changes * add documentation * fix merge issues * changes based on review * rename folder * make plot.rs the mod.rs file * remove mod.rs * rename file * namespace changes * fix doctest * Update egui/src/widgets/plot/items.rs Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> Co-authored-by: ilya sheprut <optitel223@gmail.com> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
|
Done! |
|
Thanks! |
This is something I ran into today. Types that implement
std::fmt::Displaycannot be passed to functions that takeimpl Into<String>. You have to calldisplay_thing.to_string().Its a small thing but would be avoided by instead taking
impl ToString.Afaik
impl ToStringis a superset ofimpl Into<String>, unless usersmanually implement
Into<String> for T(orFrom<T> for String) fortheir own types. However I think its more common to implement
Displayas that works with
printlnand friends. The main difference is thatDisplay::fmtcan return errors but thats also quite rare in myexperience.
I did some testing in a playground and seems to work.