From d7a5e5445561fb1bdfd1a6904b20750f29dd71fd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 17 Oct 2020 08:10:30 +0200 Subject: Require `Clone` for `Message` early when needed Prior to this change, the widgets that needed a `Clone` bound on `Message` to implement the `Widget` trait could be created with a non-cloneable `Message`. As a consequence, the compiler complained only when actually trying to use the `Widget` trait. Normally, this happens when trying to `push` the widget in a container or turn it into an `Element`. Furthermore, the compiler error in this case does not mention `Message` nor the `Clone` bound, but instead complains about a missing `From` implementation. Thus, it can easily cause confusion! This change introduces `Clone` bounds in the main implementation of the widgets that need it to properly implement the `Widget` trait. As a result, the compiler complains early when trying to create one of these widgets with a non-cloneable `Message` and explicitly mentions that the `Message` needs to implement `Clone`. --- native/src/widget/text_input.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'native/src/widget/text_input.rs') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9e15f4be..32a57ce6 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -63,7 +63,11 @@ pub struct TextInput<'a, Message, Renderer: self::Renderer> { style: Renderer::Style, } -impl<'a, Message, Renderer: self::Renderer> TextInput<'a, Message, Renderer> { +impl<'a, Message, Renderer> TextInput<'a, Message, Renderer> +where + Message: Clone, + Renderer: self::Renderer, +{ /// Creates a new [`TextInput`]. /// /// It expects: @@ -175,8 +179,8 @@ impl<'a, Message, Renderer: self::Renderer> TextInput<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for TextInput<'a, Message, Renderer> where - Renderer: self::Renderer, Message: Clone, + Renderer: self::Renderer, { fn width(&self) -> Length { self.width @@ -629,8 +633,8 @@ pub trait Renderer: text::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, Message: 'a + Clone, + Renderer: 'a + self::Renderer, { fn from( text_input: TextInput<'a, Message, Renderer>, -- cgit