mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Replace impl Into<String> with impl ToString (#302)
* Replace `impl Into<String>` with `impl ToString` 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 * Silence warnings
This commit is contained in:
@@ -340,20 +340,20 @@ pub mod http {
|
||||
|
||||
impl Request {
|
||||
/// Create a `GET` requests with the given url.
|
||||
pub fn get(url: impl Into<String>) -> Self {
|
||||
pub fn get(url: impl ToString) -> Self {
|
||||
Self {
|
||||
method: "GET".to_owned(),
|
||||
url: url.into(),
|
||||
url: url.to_string(),
|
||||
body: "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a `POST` requests with the give url and body.
|
||||
pub fn post(url: impl Into<String>, body: impl Into<String>) -> Self {
|
||||
pub fn post(url: impl ToString, body: impl ToString) -> Self {
|
||||
Self {
|
||||
method: "POST".to_owned(),
|
||||
url: url.into(),
|
||||
body: body.into(),
|
||||
url: url.to_string(),
|
||||
body: body.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user