Merge pull request #245 from tirz/refactor-bound_lifetime

refactor: remove not mandatories 'static lifetimes
This commit is contained in:
Héctor Ramón 2020-03-30 17:39:54 +02:00 committed by GitHub
commit 6e9ab1cd6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 69 additions and 50 deletions

View File

@ -37,16 +37,16 @@ members = [
"web", "web",
"wgpu", "wgpu",
"winit", "winit",
"examples/download_progress",
"examples/bezier_tool", "examples/bezier_tool",
"examples/clock", "examples/clock",
"examples/counter", "examples/counter",
"examples/custom_widget", "examples/custom_widget",
"examples/download_progress",
"examples/events", "examples/events",
"examples/geometry", "examples/geometry",
"examples/integration", "examples/integration",
"examples/pokedex",
"examples/pane_grid", "examples/pane_grid",
"examples/pokedex",
"examples/progress_bar", "examples/progress_bar",
"examples/solar_system", "examples/solar_system",
"examples/stopwatch", "examples/stopwatch",

View File

@ -143,7 +143,7 @@ impl State {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Button<'a, Message, Renderer> for Button<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
Message: Clone, Message: Clone,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
@ -234,6 +234,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Button<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.content.hash_layout(state); self.content.hash_layout(state);
} }
@ -275,7 +277,7 @@ impl<'a, Message, Renderer> From<Button<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static + Clone, Message: 'a + Clone,
{ {
fn from( fn from(
button: Button<'a, Message, Renderer>, button: Button<'a, Message, Renderer>,

View File

@ -110,7 +110,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
impl<Message, Renderer> Widget<Message, Renderer> impl<Message, Renderer> Widget<Message, Renderer>
for Checkbox<Message, Renderer> for Checkbox<Message, Renderer>
where where
Renderer: self::Renderer + text::Renderer + row::Renderer, Renderer: 'static + self::Renderer + text::Renderer + row::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -205,6 +205,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Checkbox<(), Renderer>>().hash(state);
self.label.hash(state); self.label.hash(state);
} }
} }
@ -253,7 +255,7 @@ impl<'a, Message, Renderer> From<Checkbox<Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, Renderer: 'static + self::Renderer + text::Renderer + row::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
checkbox: Checkbox<Message, Renderer>, checkbox: Checkbox<Message, Renderer>,

View File

@ -124,7 +124,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Column<'a, Message, Renderer> for Column<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -190,7 +190,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
0.hash(state); std::any::TypeId::of::<Column<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
self.max_width.hash(state); self.max_width.hash(state);
@ -233,8 +234,8 @@ pub trait Renderer: crate::Renderer + Sized {
impl<'a, Message, Renderer> From<Column<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Column<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'a + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
column: Column<'a, Message, Renderer>, column: Column<'a, Message, Renderer>,

View File

@ -122,7 +122,7 @@ where
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Container<'a, Message, Renderer> for Container<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -189,7 +189,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
0.hash(state); std::any::TypeId::of::<Container<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
self.max_width.hash(state); self.max_width.hash(state);
@ -227,8 +228,8 @@ pub trait Renderer: crate::Renderer {
impl<'a, Message, Renderer> From<Container<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Container<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'a + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
column: Container<'a, Message, Renderer>, column: Container<'a, Message, Renderer>,

View File

@ -102,6 +102,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Image>().hash(state);
self.handle.hash(state); self.handle.hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);

View File

@ -80,9 +80,9 @@ pub struct PaneGrid<'a, Message, Renderer> {
height: Length, height: Length,
spacing: u16, spacing: u16,
modifier_keys: keyboard::ModifiersState, modifier_keys: keyboard::ModifiersState,
on_drag: Option<Box<dyn Fn(DragEvent) -> Message>>, on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
on_resize: Option<Box<dyn Fn(ResizeEvent) -> Message>>, on_resize: Option<Box<dyn Fn(ResizeEvent) -> Message + 'a>>,
on_key_press: Option<Box<dyn Fn(KeyPressEvent) -> Option<Message>>>, on_key_press: Option<Box<dyn Fn(KeyPressEvent) -> Option<Message> + 'a>>,
} }
impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
@ -187,10 +187,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
/// Panes can be dragged using `Modifier keys + Left click`. /// Panes can be dragged using `Modifier keys + Left click`.
/// ///
/// [`PaneGrid`]: struct.PaneGrid.html /// [`PaneGrid`]: struct.PaneGrid.html
pub fn on_drag( pub fn on_drag<F>(mut self, f: F) -> Self
mut self, where
f: impl Fn(DragEvent) -> Message + 'static, F: 'a + Fn(DragEvent) -> Message,
) -> Self { {
self.on_drag = Some(Box::new(f)); self.on_drag = Some(Box::new(f));
self self
} }
@ -201,10 +201,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
/// Panes can be resized using `Modifier keys + Right click`. /// Panes can be resized using `Modifier keys + Right click`.
/// ///
/// [`PaneGrid`]: struct.PaneGrid.html /// [`PaneGrid`]: struct.PaneGrid.html
pub fn on_resize( pub fn on_resize<F>(mut self, f: F) -> Self
mut self, where
f: impl Fn(ResizeEvent) -> Message + 'static, F: 'a + Fn(ResizeEvent) -> Message,
) -> Self { {
self.on_resize = Some(Box::new(f)); self.on_resize = Some(Box::new(f));
self self
} }
@ -226,10 +226,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
/// ///
/// [`PaneGrid`]: struct.PaneGrid.html /// [`PaneGrid`]: struct.PaneGrid.html
/// [`Pane`]: struct.Pane.html /// [`Pane`]: struct.Pane.html
pub fn on_key_press( pub fn on_key_press<F>(mut self, f: F) -> Self
mut self, where
f: impl Fn(KeyPressEvent) -> Option<Message> + 'static, F: 'a + Fn(KeyPressEvent) -> Option<Message>,
) -> Self { {
self.on_key_press = Some(Box::new(f)); self.on_key_press = Some(Box::new(f));
self self
} }
@ -348,8 +348,7 @@ pub struct KeyPressEvent {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for PaneGrid<'a, Message, Renderer> for PaneGrid<'a, Message, Renderer>
where where
Renderer: self::Renderer + 'static, Renderer: 'static + self::Renderer,
Message: 'static,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -591,7 +590,7 @@ where
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash; use std::hash::Hash;
std::any::TypeId::of::<PaneGrid<'_, Message, Renderer>>().hash(state); std::any::TypeId::of::<PaneGrid<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
self.state.hash_layout(state); self.state.hash_layout(state);
@ -636,8 +635,8 @@ pub trait Renderer: crate::Renderer + Sized {
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>> impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: self::Renderer + 'static, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
pane_grid: PaneGrid<'a, Message, Renderer>, pane_grid: PaneGrid<'a, Message, Renderer>,

View File

@ -72,7 +72,7 @@ impl<Renderer: self::Renderer> ProgressBar<Renderer> {
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar<Renderer> impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar<Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -114,6 +114,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<ProgressBar<Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
} }
@ -158,7 +160,7 @@ impl<'a, Message, Renderer> From<ProgressBar<Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
progress_bar: ProgressBar<Renderer>, progress_bar: ProgressBar<Renderer>,

View File

@ -77,7 +77,7 @@ impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer> impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer>
where where
Renderer: self::Renderer + text::Renderer + row::Renderer, Renderer: 'static + self::Renderer + text::Renderer + row::Renderer,
Message: Clone, Message: Clone,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
@ -169,6 +169,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Radio<(), Renderer>>().hash(state);
self.label.hash(state); self.label.hash(state);
} }
} }
@ -212,7 +214,7 @@ impl<'a, Message, Renderer> From<Radio<Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer + row::Renderer + text::Renderer, Renderer: 'static + self::Renderer + row::Renderer + text::Renderer,
Message: 'static + Clone, Message: 'a + Clone,
{ {
fn from(radio: Radio<Message, Renderer>) -> Element<'a, Message, Renderer> { fn from(radio: Radio<Message, Renderer>) -> Element<'a, Message, Renderer> {
Element::new(radio) Element::new(radio)

View File

@ -125,7 +125,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Row<'a, Message, Renderer> for Row<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -191,7 +191,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
1.hash(state); std::any::TypeId::of::<Row<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
self.max_width.hash(state); self.max_width.hash(state);
@ -235,8 +236,8 @@ pub trait Renderer: crate::Renderer + Sized {
impl<'a, Message, Renderer> From<Row<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Row<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'a + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> {
Element::new(row) Element::new(row)

View File

@ -311,7 +311,7 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Scrollable<'static, (), Renderer>>().hash(state); std::any::TypeId::of::<Scrollable<'_, (), Renderer>>().hash(state);
self.height.hash(state); self.height.hash(state);
self.max_height.hash(state); self.max_height.hash(state);
@ -506,7 +506,7 @@ impl<'a, Message, Renderer> From<Scrollable<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer + column::Renderer, Renderer: 'static + self::Renderer + column::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
scrollable: Scrollable<'a, Message, Renderer>, scrollable: Scrollable<'a, Message, Renderer>,

View File

@ -114,7 +114,7 @@ impl State {
impl<'a, Message, Renderer> Widget<Message, Renderer> impl<'a, Message, Renderer> Widget<Message, Renderer>
for Slider<'a, Message, Renderer> for Slider<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: 'static + self::Renderer,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -205,6 +205,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Slider<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
} }
} }
@ -252,7 +254,7 @@ impl<'a, Message, Renderer> From<Slider<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from( fn from(
slider: Slider<'a, Message, Renderer>, slider: Slider<'a, Message, Renderer>,

View File

@ -77,6 +77,7 @@ where
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Space>().hash(state); std::any::TypeId::of::<Space>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
} }
@ -97,7 +98,7 @@ pub trait Renderer: crate::Renderer {
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: self::Renderer,
Message: 'static, Message: 'a,
{ {
fn from(space: Space) -> Element<'a, Message, Renderer> { fn from(space: Space) -> Element<'a, Message, Renderer> {
Element::new(space) Element::new(space)

View File

@ -99,6 +99,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Svg>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
} }

View File

@ -163,6 +163,8 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Text>().hash(state);
self.content.hash(state); self.content.hash(state);
self.size.hash(state); self.size.hash(state);
self.width.hash(state); self.width.hash(state);

View File

@ -172,7 +172,7 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
for TextInput<'a, Message, Renderer> for TextInput<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer, Renderer: 'static + self::Renderer,
Message: Clone + std::fmt::Debug, Message: Clone,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -501,7 +501,7 @@ where
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
use std::{any::TypeId, hash::Hash}; use std::{any::TypeId, hash::Hash};
TypeId::of::<TextInput<'static, (), Renderer>>().hash(state); TypeId::of::<TextInput<'_, (), Renderer>>().hash(state);
self.width.hash(state); self.width.hash(state);
self.max_width.hash(state); self.max_width.hash(state);
@ -607,7 +607,7 @@ impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>>
for Element<'a, Message, Renderer> for Element<'a, Message, Renderer>
where where
Renderer: 'static + self::Renderer, Renderer: 'static + self::Renderer,
Message: 'static + Clone + std::fmt::Debug, Message: 'a + Clone,
{ {
fn from( fn from(
text_input: TextInput<'a, Message, Renderer>, text_input: TextInput<'a, Message, Renderer>,