From fd26202023590aed39f1fc0fb1a65edc9441d678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 12 Oct 2022 22:48:30 +0200 Subject: [PATCH] Implement `From` instead of `Into` for widgets --- pure/src/widget/button.rs | 8 ++++---- pure/src/widget/checkbox.rs | 12 +++++++----- pure/src/widget/column.rs | 8 ++++---- pure/src/widget/image.rs | 11 +++++------ pure/src/widget/pick_list.rs | 8 ++++---- pure/src/widget/progress_bar.rs | 13 ++++++++----- pure/src/widget/radio.rs | 10 +++++----- pure/src/widget/row.rs | 8 ++++---- pure/src/widget/rule.rs | 11 ++++++----- pure/src/widget/space.rs | 9 +++++---- pure/src/widget/svg.rs | 9 ++++----- pure/src/widget/text.rs | 14 +++++++------- pure/src/widget/toggler.rs | 12 +++++++----- 13 files changed, 70 insertions(+), 63 deletions(-) diff --git a/pure/src/widget/button.rs b/pure/src/widget/button.rs index dd7688e2ec..120e8eb580 100644 --- a/pure/src/widget/button.rs +++ b/pure/src/widget/button.rs @@ -261,14 +261,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Button<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: Clone + 'a, Renderer: iced_native::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(button: Button<'a, Message, Renderer>) -> Self { + Self::new(button) } } diff --git a/pure/src/widget/checkbox.rs b/pure/src/widget/checkbox.rs index 9d6a78cee9..25d846a4b0 100644 --- a/pure/src/widget/checkbox.rs +++ b/pure/src/widget/checkbox.rs @@ -96,14 +96,16 @@ where } } -impl<'a, Message, Renderer> Into> - for Checkbox<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, - Renderer: text::Renderer + 'a, + Renderer: 'a + text::Renderer, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from( + checkbox: Checkbox<'a, Message, Renderer>, + ) -> Element<'a, Message, Renderer> { + Element::new(checkbox) } } diff --git a/pure/src/widget/column.rs b/pure/src/widget/column.rs index 74d789a173..84b85c6471 100644 --- a/pure/src/widget/column.rs +++ b/pure/src/widget/column.rs @@ -228,13 +228,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Column<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: iced_native::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(column: Column<'a, Message, Renderer>) -> Self { + Self::new(column) } } diff --git a/pure/src/widget/image.rs b/pure/src/widget/image.rs index c42113dcae..1d0f40f621 100644 --- a/pure/src/widget/image.rs +++ b/pure/src/widget/image.rs @@ -56,14 +56,13 @@ where } } -impl<'a, Message, Renderer, Handle> Into> - for Image +impl<'a, Message, Renderer, Handle> From> + for Element<'a, Message, Renderer> where - Message: Clone + 'a, - Renderer: iced_native::image::Renderer + 'a, + Renderer: iced_native::image::Renderer, Handle: Clone + Hash + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(image: Image) -> Element<'a, Message, Renderer> { + Element::new(image) } } diff --git a/pure/src/widget/pick_list.rs b/pure/src/widget/pick_list.rs index 2c46593257..0dfd181840 100644 --- a/pure/src/widget/pick_list.rs +++ b/pure/src/widget/pick_list.rs @@ -225,8 +225,8 @@ where } } -impl<'a, T: 'a, Message, Renderer> Into> - for PickList<'a, T, Message, Renderer> +impl<'a, T: 'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where T: Clone + ToString + Eq + 'static, [T]: ToOwned>, @@ -234,7 +234,7 @@ where Renderer: text::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(pick_list: PickList<'a, T, Message, Renderer>) -> Self { + Self::new(pick_list) } } diff --git a/pure/src/widget/progress_bar.rs b/pure/src/widget/progress_bar.rs index 69c7d30226..32f07511f3 100644 --- a/pure/src/widget/progress_bar.rs +++ b/pure/src/widget/progress_bar.rs @@ -93,13 +93,16 @@ where } } -impl<'a, Message, Renderer> Into> - for ProgressBar +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where - Renderer: iced_native::Renderer + 'a, + Message: 'a, + Renderer: 'a + iced_native::Renderer, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from( + progress_bar: ProgressBar, + ) -> Element<'a, Message, Renderer> { + Element::new(progress_bar) } } diff --git a/pure/src/widget/radio.rs b/pure/src/widget/radio.rs index 7a6ffbac12..290dbd03e1 100644 --- a/pure/src/widget/radio.rs +++ b/pure/src/widget/radio.rs @@ -96,14 +96,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Radio +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a + Clone, - Renderer: text::Renderer + 'a, + Renderer: 'a + text::Renderer, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(radio: Radio) -> Element<'a, Message, Renderer> { + Element::new(radio) } } diff --git a/pure/src/widget/row.rs b/pure/src/widget/row.rs index e747adfc42..5c47d56f2b 100644 --- a/pure/src/widget/row.rs +++ b/pure/src/widget/row.rs @@ -215,13 +215,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Row<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: iced_native::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(row: Row<'a, Message, Renderer>) -> Self { + Self::new(row) } } diff --git a/pure/src/widget/rule.rs b/pure/src/widget/rule.rs index 66a476536f..5b33dd4eea 100644 --- a/pure/src/widget/rule.rs +++ b/pure/src/widget/rule.rs @@ -93,13 +93,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Rule +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where - Renderer: iced_native::Renderer + 'a, + Message: 'a, + Renderer: 'a + iced_native::Renderer, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(rule: Rule) -> Element<'a, Message, Renderer> { + Element::new(rule) } } diff --git a/pure/src/widget/space.rs b/pure/src/widget/space.rs index 7d95ebd7ea..ef7212e627 100644 --- a/pure/src/widget/space.rs +++ b/pure/src/widget/space.rs @@ -91,11 +91,12 @@ where } } -impl<'a, Message, Renderer> Into> for Space +impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where - Renderer: iced_native::Renderer + 'a, + Renderer: iced_native::Renderer, + Message: 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(space: Space) -> Element<'a, Message, Renderer> { + Element::new(space) } } diff --git a/pure/src/widget/svg.rs b/pure/src/widget/svg.rs index 501d9bfaad..c6b7e15f94 100644 --- a/pure/src/widget/svg.rs +++ b/pure/src/widget/svg.rs @@ -54,12 +54,11 @@ where } } -impl<'a, Message, Renderer> Into> for Svg +impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where - Message: Clone + 'a, - Renderer: iced_native::svg::Renderer + 'a, + Renderer: iced_native::svg::Renderer, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(icon: Svg) -> Element<'a, Message, Renderer> { + Element::new(icon) } } diff --git a/pure/src/widget/text.rs b/pure/src/widget/text.rs index 23999a2cff..6a22b96696 100644 --- a/pure/src/widget/text.rs +++ b/pure/src/widget/text.rs @@ -55,23 +55,23 @@ where } } -impl<'a, Message, Renderer> Into> - for Text +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Renderer: text::Renderer + 'a, Renderer::Theme: widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(text: Text) -> Self { + Self::new(text) } } -impl<'a, Message, Renderer> Into> for &'a str +impl<'a, Message, Renderer> From<&'a str> for Element<'a, Message, Renderer> where Renderer: text::Renderer + 'a, Renderer::Theme: widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Text::new(self).into() + fn from(content: &'a str) -> Self { + Element::from(Text::new(content)) } } diff --git a/pure/src/widget/toggler.rs b/pure/src/widget/toggler.rs index 5efa39ab31..db518a53cf 100644 --- a/pure/src/widget/toggler.rs +++ b/pure/src/widget/toggler.rs @@ -96,14 +96,16 @@ where } } -impl<'a, Message, Renderer> Into> - for Toggler<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, - Renderer: text::Renderer + 'a, + Renderer: 'a + text::Renderer, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from( + toggler: Toggler<'a, Message, Renderer>, + ) -> Element<'a, Message, Renderer> { + Element::new(toggler) } }