From 0539cd1b85d00a2accca200184a5980527851539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gaillard?= Date: Mon, 30 Mar 2020 06:30:22 +0800 Subject: [PATCH] refactor: remove not mandatory static lifetime --- Cargo.toml | 4 ++-- native/src/widget/button.rs | 4 ++-- native/src/widget/checkbox.rs | 4 ++-- native/src/widget/column.rs | 2 +- native/src/widget/container.rs | 2 +- native/src/widget/pane_grid.rs | 28 ++++++++++++++-------------- native/src/widget/progress_bar.rs | 4 ++-- native/src/widget/radio.rs | 4 ++-- native/src/widget/row.rs | 2 +- native/src/widget/scrollable.rs | 2 +- native/src/widget/slider.rs | 4 ++-- native/src/widget/space.rs | 2 +- native/src/widget/text_input.rs | 2 +- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d2444486..1ba7db45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,16 +37,16 @@ members = [ "web", "wgpu", "winit", - "examples/download_progress", "examples/bezier_tool", "examples/clock", "examples/counter", "examples/custom_widget", + "examples/download_progress", "examples/events", "examples/geometry", "examples/integration", - "examples/pokedex", "examples/pane_grid", + "examples/pokedex", "examples/progress_bar", "examples/solar_system", "examples/stopwatch", diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index f1d46936..24a8bf94 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -274,8 +274,8 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'static + self::Renderer, - Message: 'static + Clone, + Renderer: 'a + self::Renderer, + Message: 'a + Clone, { fn from( button: Button<'a, Message, Renderer>, diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index b36d10a4..4e807f77 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -252,8 +252,8 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, - Message: 'static, + Renderer: 'a + self::Renderer + text::Renderer + row::Renderer, + Message: 'a, { fn from( checkbox: Checkbox, diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index b1adc6e3..43cf873a 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -234,7 +234,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'a + self::Renderer, - Message: 'static, + Message: 'a, { fn from( column: Column<'a, Message, Renderer>, diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index d1cbb32e..db266d4f 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -228,7 +228,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'a + self::Renderer, - Message: 'static, + Message: 'a, { fn from( column: Container<'a, Message, Renderer>, diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index a88f591a..9699abfc 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -187,10 +187,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// Panes can be dragged using `Modifier keys + Left click`. /// /// [`PaneGrid`]: struct.PaneGrid.html - pub fn on_drag( - mut self, - f: impl Fn(DragEvent) -> Message + 'static, - ) -> Self { + pub fn on_drag(mut self, f: F) -> Self + where + F: 'static + Fn(DragEvent) -> Message, + { self.on_drag = Some(Box::new(f)); self } @@ -201,10 +201,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// Panes can be resized using `Modifier keys + Right click`. /// /// [`PaneGrid`]: struct.PaneGrid.html - pub fn on_resize( - mut self, - f: impl Fn(ResizeEvent) -> Message + 'static, - ) -> Self { + pub fn on_resize(mut self, f: F) -> Self + where + F: 'static + Fn(ResizeEvent) -> Message, + { self.on_resize = Some(Box::new(f)); self } @@ -226,10 +226,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// /// [`PaneGrid`]: struct.PaneGrid.html /// [`Pane`]: struct.Pane.html - pub fn on_key_press( - mut self, - f: impl Fn(KeyPressEvent) -> Option + 'static, - ) -> Self { + pub fn on_key_press(mut self, f: F) -> Self + where + F: 'static + Fn(KeyPressEvent) -> Option, + { self.on_key_press = Some(Box::new(f)); self } @@ -348,7 +348,7 @@ pub struct KeyPressEvent { impl<'a, Message, Renderer> Widget for PaneGrid<'a, Message, Renderer> where - Renderer: self::Renderer + 'static, + Renderer: 'static + self::Renderer, Message: 'static, { fn width(&self) -> Length { @@ -636,7 +636,7 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: self::Renderer + 'static, + Renderer: 'static + self::Renderer, Message: 'static, { fn from( diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index 67d1ab83..90b3af62 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -157,8 +157,8 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'static + self::Renderer, - Message: 'static, + Renderer: 'a + self::Renderer, + Message: 'a, { fn from( progress_bar: ProgressBar, diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index cdc4862c..d4795cc9 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -211,8 +211,8 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'static + self::Renderer + row::Renderer + text::Renderer, - Message: 'static + Clone, + Renderer: 'a + self::Renderer + row::Renderer + text::Renderer, + Message: 'a + Clone, { fn from(radio: Radio) -> Element<'a, Message, Renderer> { Element::new(radio) diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index c8812ea2..7689abbf 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -236,7 +236,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'a + self::Renderer, - Message: 'static, + Message: 'a, { fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { Element::new(row) diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index ec9746d4..cd4a9dfa 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -506,7 +506,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer + column::Renderer, - Message: 'static, + Message: 'a, { fn from( scrollable: Scrollable<'a, Message, Renderer>, diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index 008203fe..f771d57a 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -251,8 +251,8 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'static + self::Renderer, - Message: 'static, + Renderer: 'a + self::Renderer, + Message: 'a, { fn from( slider: Slider<'a, Message, Renderer>, diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs index 24c94bf6..392f2319 100644 --- a/native/src/widget/space.rs +++ b/native/src/widget/space.rs @@ -97,7 +97,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where Renderer: self::Renderer, - Message: 'static, + Message: 'a, { fn from(space: Space) -> Element<'a, Message, Renderer> { Element::new(space) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c17a1d30..fc939408 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -607,7 +607,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static + Clone + std::fmt::Debug, + Message: 'a + Clone + std::fmt::Debug, { fn from( text_input: TextInput<'a, Message, Renderer>,