From 15f5b93a0d4b7b7fead8d1864c77e6df50b9a231 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sat, 4 Apr 2020 13:21:45 +0700 Subject: [PATCH 1/3] Checkbox label is now `impl Into` --- native/src/widget/checkbox.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 7f91545649..ccf1384823 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -50,14 +50,14 @@ impl /// `Message`. /// /// [`Checkbox`]: struct.Checkbox.html - pub fn new(is_checked: bool, label: &str, f: F) -> Self + pub fn new(is_checked: bool, label: impl Into, f: F) -> Self where F: 'static + Fn(bool) -> Message, { Checkbox { is_checked, on_toggle: Box::new(f), - label: String::from(label), + label: label.into(), width: Length::Shrink, size: ::DEFAULT_SIZE, spacing: Renderer::DEFAULT_SPACING, From 1a9bfd9e737c4203c9ec607465c106da08ad5020 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Sun, 5 Apr 2020 10:29:25 +0700 Subject: [PATCH 2/3] Radiobutton label is now `impl Into` --- examples/tour/src/main.rs | 3 ++- native/src/widget/radio.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 800254edf0..0928cf300f 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -528,9 +528,10 @@ impl<'a> Step { .push(Language::all().iter().cloned().fold( Column::new().padding(10).spacing(20), |choices, language| { + let label: &str = language.into(); choices.push(Radio::new( language, - language.into(), + label, selection, StepMessage::LanguageSelected, )) diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index 8fb3d0cc61..bc23c1163a 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -53,7 +53,12 @@ impl Radio { /// receives the value of the radio and must produce a `Message`. /// /// [`Radio`]: struct.Radio.html - pub fn new(value: V, label: &str, selected: Option, f: F) -> Self + pub fn new( + value: V, + label: impl Into, + selected: Option, + f: F, + ) -> Self where V: Eq + Copy, F: 'static + Fn(V) -> Message, @@ -61,7 +66,7 @@ impl Radio { Radio { is_selected: Some(value) == selected, on_click: f(value), - label: String::from(label), + label: label.into(), style: Renderer::Style::default(), } } From 3c47e3e2295e2dd6ca60e50111b9b89a4bb025fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 6 Apr 2020 20:12:16 +0200 Subject: [PATCH 3/3] Simplify `Language` conversion in `tour` --- examples/tour/src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 0928cf300f..c9678b9d49 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -528,10 +528,9 @@ impl<'a> Step { .push(Language::all().iter().cloned().fold( Column::new().padding(10).spacing(20), |choices, language| { - let label: &str = language.into(); choices.push(Radio::new( language, - label, + language, selection, StepMessage::LanguageSelected, )) @@ -730,16 +729,16 @@ impl Language { } } -impl From for &str { - fn from(language: Language) -> &'static str { - match language { +impl From for String { + fn from(language: Language) -> String { + String::from(match language { Language::Rust => "Rust", Language::Elm => "Elm", Language::Ruby => "Ruby", Language::Haskell => "Haskell", Language::C => "C", Language::Other => "Other", - } + }) } }