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`. --- examples/color_palette/src/main.rs | 2 +- examples/tour/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs index fec5f48c..bb2c61cb 100644 --- a/examples/color_palette/src/main.rs +++ b/examples/color_palette/src/main.rs @@ -284,7 +284,7 @@ impl ColorPicker { let [s1, s2, s3] = &mut self.sliders; let [cr1, cr2, cr3] = C::COMPONENT_RANGES; - fn slider( + fn slider( state: &mut slider::State, range: RangeInclusive, component: f32, diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index ec464801..560d67e2 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -689,7 +689,7 @@ fn ferris<'a>(width: u16) -> Container<'a, StepMessage> { .center_x() } -fn button<'a, Message>( +fn button<'a, Message: Clone>( state: &'a mut button::State, label: &str, ) -> Button<'a, Message> { -- cgit