diff options
author | 2020-10-17 08:10:30 +0200 | |
---|---|---|
committer | 2020-10-17 08:10:30 +0200 | |
commit | d7a5e5445561fb1bdfd1a6904b20750f29dd71fd (patch) | |
tree | 0255f294ce03a71c543617271bab3f32ea33b211 /native/src/widget/slider.rs | |
parent | 17f0db57c3be440642a057e0a53106fcecdf4564 (diff) | |
download | iced-d7a5e5445561fb1bdfd1a6904b20750f29dd71fd.tar.gz iced-d7a5e5445561fb1bdfd1a6904b20750f29dd71fd.tar.bz2 iced-d7a5e5445561fb1bdfd1a6904b20750f29dd71fd.zip |
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`.
Diffstat (limited to 'native/src/widget/slider.rs')
-rw-r--r-- | native/src/widget/slider.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index c49053f1..3255dd04 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -26,6 +26,7 @@ use std::{hash::Hash, ops::RangeInclusive}; /// # use iced_native::{slider, renderer::Null}; /// # /// # pub type Slider<'a, T, Message> = iced_native::Slider<'a, T, Message, Null>; +/// #[derive(Clone)] /// pub enum Message { /// SliderChanged(f32), /// } @@ -53,6 +54,7 @@ pub struct Slider<'a, T, Message, Renderer: self::Renderer> { impl<'a, T, Message, Renderer> Slider<'a, T, Message, Renderer> where T: Copy + From<u8> + std::cmp::PartialOrd, + Message: Clone, Renderer: self::Renderer, { /// Creates a new [`Slider`]. @@ -168,8 +170,8 @@ impl<'a, T, Message, Renderer> Widget<Message, Renderer> for Slider<'a, T, Message, Renderer> where T: Copy + Into<f64> + num_traits::FromPrimitive, - Renderer: self::Renderer, Message: Clone, + Renderer: self::Renderer, { fn width(&self) -> Length { self.width @@ -322,8 +324,8 @@ impl<'a, T, Message, Renderer> From<Slider<'a, T, Message, Renderer>> for Element<'a, Message, Renderer> where T: 'a + Copy + Into<f64> + num_traits::FromPrimitive, - Renderer: 'a + self::Renderer, Message: 'a + Clone, + Renderer: 'a + self::Renderer, { fn from( slider: Slider<'a, T, Message, Renderer>, |