From d07304fb85c4ea7293b61c5d0a366ffbbc511de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 30 Mar 2020 17:28:55 +0200 Subject: [PATCH] Hash type ids in `Widget::hash_layout` impls --- native/src/widget/button.rs | 6 ++++-- native/src/widget/checkbox.rs | 6 ++++-- native/src/widget/column.rs | 7 ++++--- native/src/widget/container.rs | 7 ++++--- native/src/widget/image.rs | 2 ++ native/src/widget/pane_grid.rs | 17 ++++++++--------- native/src/widget/progress_bar.rs | 6 ++++-- native/src/widget/radio.rs | 6 ++++-- native/src/widget/row.rs | 7 ++++--- native/src/widget/scrollable.rs | 2 +- native/src/widget/slider.rs | 6 ++++-- native/src/widget/space.rs | 1 + native/src/widget/svg.rs | 2 ++ native/src/widget/text.rs | 2 ++ native/src/widget/text_input.rs | 6 +++--- 15 files changed, 51 insertions(+), 32 deletions(-) diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 24a8bf94..7b5c349c 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -143,7 +143,7 @@ impl State { impl<'a, Message, Renderer> Widget for Button<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, Message: Clone, { fn width(&self) -> Length { @@ -234,6 +234,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.content.hash_layout(state); } @@ -274,7 +276,7 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a + Clone, { fn from( diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 4e807f77..7f915456 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -110,7 +110,7 @@ impl impl Widget for Checkbox where - Renderer: self::Renderer + text::Renderer + row::Renderer, + Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, { fn width(&self) -> Length { self.width @@ -205,6 +205,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.label.hash(state); } } @@ -252,7 +254,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer + text::Renderer + row::Renderer, + Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, Message: 'a, { fn from( diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 43cf873a..77b8496b 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -124,7 +124,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for Column<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -190,7 +190,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 0.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -233,7 +234,7 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a, { fn from( diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index db266d4f..11ef23a9 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -122,7 +122,7 @@ where impl<'a, Message, Renderer> Widget for Container<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -189,7 +189,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 0.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -227,7 +228,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a, { fn from( diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 5b067687..9dc13fa9 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -102,6 +102,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.handle.hash(state); self.width.hash(state); self.height.hash(state); diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 9699abfc..2eca68d3 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -80,9 +80,9 @@ pub struct PaneGrid<'a, Message, Renderer> { height: Length, spacing: u16, modifier_keys: keyboard::ModifiersState, - on_drag: Option Message>>, - on_resize: Option Message>>, - on_key_press: Option Option>>, + on_drag: Option Message + 'a>>, + on_resize: Option Message + 'a>>, + on_key_press: Option Option + 'a>>, } impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { @@ -189,7 +189,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// [`PaneGrid`]: struct.PaneGrid.html pub fn on_drag(mut self, f: F) -> Self where - F: 'static + Fn(DragEvent) -> Message, + F: 'a + Fn(DragEvent) -> Message, { self.on_drag = Some(Box::new(f)); self @@ -203,7 +203,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// [`PaneGrid`]: struct.PaneGrid.html pub fn on_resize(mut self, f: F) -> Self where - F: 'static + Fn(ResizeEvent) -> Message, + F: 'a + Fn(ResizeEvent) -> Message, { self.on_resize = Some(Box::new(f)); self @@ -228,7 +228,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// [`Pane`]: struct.Pane.html pub fn on_key_press(mut self, f: F) -> Self where - F: 'static + Fn(KeyPressEvent) -> Option, + F: 'a + Fn(KeyPressEvent) -> Option, { self.on_key_press = Some(Box::new(f)); self @@ -349,7 +349,6 @@ impl<'a, Message, Renderer> Widget for PaneGrid<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static, { fn width(&self) -> Length { self.width @@ -591,7 +590,7 @@ where fn hash_layout(&self, state: &mut Hasher) { use std::hash::Hash; - std::any::TypeId::of::>().hash(state); + std::any::TypeId::of::>().hash(state); self.width.hash(state); self.height.hash(state); self.state.hash_layout(state); @@ -637,7 +636,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static, + Message: 'a, { fn from( pane_grid: PaneGrid<'a, Message, Renderer>, diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index 90b3af62..897edb30 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -72,7 +72,7 @@ impl ProgressBar { impl Widget for ProgressBar where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -114,6 +114,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); } @@ -157,7 +159,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a, { fn from( diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index d4795cc9..8fb3d0cc 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -77,7 +77,7 @@ impl Radio { impl Widget for Radio where - Renderer: self::Renderer + text::Renderer + row::Renderer, + Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, Message: Clone, { fn width(&self) -> Length { @@ -169,6 +169,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.label.hash(state); } } @@ -211,7 +213,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer + row::Renderer + text::Renderer, + Renderer: 'static + self::Renderer + row::Renderer + text::Renderer, Message: 'a + Clone, { fn from(radio: Radio) -> Element<'a, Message, Renderer> { diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index 7689abbf..5f139f66 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -125,7 +125,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for Row<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -191,7 +191,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 1.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -235,7 +236,7 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a, { fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index cd4a9dfa..ba39edb1 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -311,7 +311,7 @@ where } fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::>().hash(state); + std::any::TypeId::of::>().hash(state); self.height.hash(state); self.max_height.hash(state); diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index f771d57a..b2fa5c9d 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -114,7 +114,7 @@ impl State { impl<'a, Message, Renderer> Widget for Slider<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -205,6 +205,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); } } @@ -251,7 +253,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, + Renderer: 'static + self::Renderer, Message: 'a, { fn from( diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs index 392f2319..e56a8fe1 100644 --- a/native/src/widget/space.rs +++ b/native/src/widget/space.rs @@ -77,6 +77,7 @@ where fn hash_layout(&self, state: &mut Hasher) { std::any::TypeId::of::().hash(state); + self.width.hash(state); self.height.hash(state); } diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index b899da1e..4a227f3d 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -99,6 +99,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.width.hash(state); self.height.hash(state); } diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index 7d8cad6e..dc7c33ec 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -163,6 +163,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.content.hash(state); self.size.hash(state); self.width.hash(state); diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index fc939408..3697ce09 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -172,7 +172,7 @@ impl<'a, Message, Renderer> Widget for TextInput<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: Clone + std::fmt::Debug, + Message: Clone, { fn width(&self) -> Length { self.width @@ -501,7 +501,7 @@ where fn hash_layout(&self, state: &mut Hasher) { use std::{any::TypeId, hash::Hash}; - TypeId::of::>().hash(state); + TypeId::of::>().hash(state); self.width.hash(state); self.max_width.hash(state); @@ -607,7 +607,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'a + Clone + std::fmt::Debug, + Message: 'a + Clone, { fn from( text_input: TextInput<'a, Message, Renderer>,