From f81827c151eba868ab17f35d21a654d48125d0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 6 Mar 2020 03:30:48 +0100 Subject: [PATCH] Remove counterintuitive constant functions --- native/src/layout/limits.rs | 4 ++-- native/src/layout/node.rs | 4 ++-- native/src/widget/column.rs | 16 ++++++++-------- native/src/widget/image.rs | 4 ++-- native/src/widget/row.rs | 16 ++++++++-------- native/src/widget/slider.rs | 4 ++-- native/src/widget/text_input.rs | 11 ++++------- web/src/widget/button.rs | 4 ++-- web/src/widget/column.rs | 16 ++++++++-------- web/src/widget/row.rs | 16 ++++++++-------- web/src/widget/scrollable.rs | 4 ++-- web/src/widget/slider.rs | 2 +- web/src/widget/text_input.rs | 4 ++-- wgpu/src/renderer.rs | 2 +- 14 files changed, 52 insertions(+), 55 deletions(-) diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs index 5f456871..740417d4 100644 --- a/native/src/layout/limits.rs +++ b/native/src/layout/limits.rs @@ -32,7 +32,7 @@ impl Limits { /// /// [`Limits`]: struct.Limits.html /// [`Size`]: ../struct.Size.html - pub const fn min(&self) -> Size { + pub fn min(&self) -> Size { self.min } @@ -40,7 +40,7 @@ impl Limits { /// /// [`Limits`]: struct.Limits.html /// [`Size`]: ../struct.Size.html - pub const fn max(&self) -> Size { + pub fn max(&self) -> Size { self.max } diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index 3b63914e..acfd33bd 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -36,14 +36,14 @@ impl Node { /// /// [`Node`]: struct.Node.html /// [`Size`]: ../struct.Size.html - pub const fn size(&self) -> Size { + pub fn size(&self) -> Size { Size::new(self.bounds.width, self.bounds.height) } /// Returns the bounds of the [`Node`]. /// /// [`Node`]: struct.Node.html - pub const fn bounds(&self) -> Rectangle { + pub fn bounds(&self) -> Rectangle { self.bounds } diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 104fdb94..cdcf25af 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -28,7 +28,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Creates an empty [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn new() -> Self { + pub fn new() -> Self { Column { spacing: 0, padding: 0, @@ -46,7 +46,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Custom margins per element do not exist in Iced. You should use this /// method instead! While less flexible, it helps you keep spacing between /// elements consistent. - pub const fn spacing(mut self, units: u16) -> Self { + pub fn spacing(mut self, units: u16) -> Self { self.spacing = units; self } @@ -54,7 +54,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the padding of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn padding(mut self, units: u16) -> Self { + pub fn padding(mut self, units: u16) -> Self { self.padding = units; self } @@ -62,7 +62,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the width of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn width(mut self, width: Length) -> Self { + pub fn width(mut self, width: Length) -> Self { self.width = width; self } @@ -70,7 +70,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the height of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn height(mut self, height: Length) -> Self { + pub fn height(mut self, height: Length) -> Self { self.height = height; self } @@ -78,7 +78,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the maximum width of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } @@ -86,7 +86,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the maximum height of the [`Column`] in pixels. /// /// [`Column`]: struct.Column.html - pub const fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: u32) -> Self { self.max_height = max_height; self } @@ -94,7 +94,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { /// Sets the horizontal alignment of the contents of the [`Column`] . /// /// [`Column`]: struct.Column.html - pub const fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: Align) -> Self { self.align_items = align; self } diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 5cfe074f..4c588c9d 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -37,7 +37,7 @@ impl Image { /// Sets the width of the [`Image`] boundaries. /// /// [`Image`]: struct.Image.html - pub const fn width(mut self, width: Length) -> Self { + pub fn width(mut self, width: Length) -> Self { self.width = width; self } @@ -45,7 +45,7 @@ impl Image { /// Sets the height of the [`Image`] boundaries. /// /// [`Image`]: struct.Image.html - pub const fn height(mut self, height: Length) -> Self { + pub fn height(mut self, height: Length) -> Self { self.height = height; self } diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index e9b8654c..c854aff7 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -28,7 +28,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Creates an empty [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn new() -> Self { + pub fn new() -> Self { Row { spacing: 0, padding: 0, @@ -46,7 +46,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Custom margins per element do not exist in Iced. You should use this /// method instead! While less flexible, it helps you keep spacing between /// elements consistent. - pub const fn spacing(mut self, units: u16) -> Self { + pub fn spacing(mut self, units: u16) -> Self { self.spacing = units; self } @@ -54,7 +54,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the padding of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn padding(mut self, units: u16) -> Self { + pub fn padding(mut self, units: u16) -> Self { self.padding = units; self } @@ -62,7 +62,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the width of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn width(mut self, width: Length) -> Self { + pub fn width(mut self, width: Length) -> Self { self.width = width; self } @@ -70,7 +70,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the height of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn height(mut self, height: Length) -> Self { + pub fn height(mut self, height: Length) -> Self { self.height = height; self } @@ -78,7 +78,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the maximum width of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } @@ -86,7 +86,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the maximum height of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: u32) -> Self { self.max_height = max_height; self } @@ -94,7 +94,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { /// Sets the vertical alignment of the contents of the [`Row`] . /// /// [`Row`]: struct.Row.html - pub const fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: Align) -> Self { self.align_items = align; self } diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index a8915da1..f07ea7cd 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -95,8 +95,8 @@ impl State { /// Creates a new [`State`]. /// /// [`State`]: struct.State.html - pub const fn new() -> State { - State { is_dragging: false } + pub fn new() -> State { + State::default() } } diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 0246f0d5..f97ed424 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -326,17 +326,14 @@ impl State { /// Creates a new [`State`], representing an unfocused [`TextInput`]. /// /// [`State`]: struct.State.html - pub const fn new() -> Self { - Self { - is_focused: false, - cursor_position: 0, - } + pub fn new() -> Self { + Self::default() } /// Creates a new [`State`], representing a focused [`TextInput`]. /// /// [`State`]: struct.State.html - pub const fn focused() -> Self { + pub fn focused() -> Self { use std::usize; Self { @@ -348,7 +345,7 @@ impl State { /// Returns whether the [`TextInput`] is currently focused or not. /// /// [`TextInput`]: struct.TextInput.html - pub const fn is_focused(&self) -> bool { + pub fn is_focused(&self) -> bool { self.is_focused } diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 13b47077..889c0ab1 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -113,8 +113,8 @@ impl State { /// Creates a new [`State`]. /// /// [`State`]: struct.State.html - pub const fn new() -> State { - State + pub fn new() -> State { + State::default() } } diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index 82b533dd..cc850f5f 100644 --- a/web/src/widget/column.rs +++ b/web/src/widget/column.rs @@ -24,7 +24,7 @@ impl<'a, Message> Column<'a, Message> { /// Creates an empty [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn new() -> Self { + pub fn new() -> Self { Column { spacing: 0, padding: 0, @@ -42,7 +42,7 @@ impl<'a, Message> Column<'a, Message> { /// Custom margins per element do not exist in Iced. You should use this /// method instead! While less flexible, it helps you keep spacing between /// elements consistent. - pub const fn spacing(mut self, units: u16) -> Self { + pub fn spacing(mut self, units: u16) -> Self { self.spacing = units; self } @@ -50,7 +50,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the padding of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn padding(mut self, units: u16) -> Self { + pub fn padding(mut self, units: u16) -> Self { self.padding = units; self } @@ -58,7 +58,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the width of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn width(mut self, width: Length) -> Self { + pub fn width(mut self, width: Length) -> Self { self.width = width; self } @@ -66,7 +66,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the height of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn height(mut self, height: Length) -> Self { + pub fn height(mut self, height: Length) -> Self { self.height = height; self } @@ -74,7 +74,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the maximum width of the [`Column`]. /// /// [`Column`]: struct.Column.html - pub const fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } @@ -82,7 +82,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the maximum height of the [`Column`] in pixels. /// /// [`Column`]: struct.Column.html - pub const fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: u32) -> Self { self.max_height = max_height; self } @@ -90,7 +90,7 @@ impl<'a, Message> Column<'a, Message> { /// Sets the horizontal alignment of the contents of the [`Column`] . /// /// [`Column`]: struct.Column.html - pub const fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: Align) -> Self { self.align_items = align; self } diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs index 0b4cec54..e47478be 100644 --- a/web/src/widget/row.rs +++ b/web/src/widget/row.rs @@ -24,7 +24,7 @@ impl<'a, Message> Row<'a, Message> { /// Creates an empty [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn new() -> Self { + pub fn new() -> Self { Row { spacing: 0, padding: 0, @@ -42,7 +42,7 @@ impl<'a, Message> Row<'a, Message> { /// Custom margins per element do not exist in Iced. You should use this /// method instead! While less flexible, it helps you keep spacing between /// elements consistent. - pub const fn spacing(mut self, units: u16) -> Self { + pub fn spacing(mut self, units: u16) -> Self { self.spacing = units; self } @@ -50,7 +50,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the padding of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn padding(mut self, units: u16) -> Self { + pub fn padding(mut self, units: u16) -> Self { self.padding = units; self } @@ -58,7 +58,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the width of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn width(mut self, width: Length) -> Self { + pub fn width(mut self, width: Length) -> Self { self.width = width; self } @@ -66,7 +66,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the height of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn height(mut self, height: Length) -> Self { + pub fn height(mut self, height: Length) -> Self { self.height = height; self } @@ -74,7 +74,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the maximum width of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } @@ -82,7 +82,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the maximum height of the [`Row`]. /// /// [`Row`]: struct.Row.html - pub const fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: u32) -> Self { self.max_height = max_height; self } @@ -90,7 +90,7 @@ impl<'a, Message> Row<'a, Message> { /// Sets the vertical alignment of the contents of the [`Row`] . /// /// [`Row`]: struct.Row.html - pub const fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: Align) -> Self { self.align_items = align; self } diff --git a/web/src/widget/scrollable.rs b/web/src/widget/scrollable.rs index 65766d74..710bb70a 100644 --- a/web/src/widget/scrollable.rs +++ b/web/src/widget/scrollable.rs @@ -151,7 +151,7 @@ impl State { /// Creates a new [`State`] with the scrollbar located at the top. /// /// [`State`]: struct.State.html - pub const fn new() -> Self { - State + pub fn new() -> Self { + State::default() } } diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index 55848084..5b203e07 100644 --- a/web/src/widget/slider.rs +++ b/web/src/widget/slider.rs @@ -147,7 +147,7 @@ impl State { /// Creates a new [`State`]. /// /// [`State`]: struct.State.html - pub const fn new() -> Self { + pub fn new() -> Self { Self } } diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 04c3b287..d6357512 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -191,7 +191,7 @@ impl State { /// Creates a new [`State`], representing an unfocused [`TextInput`]. /// /// [`State`]: struct.State.html - pub const fn new() -> Self { - Self + pub fn new() -> Self { + Self::default() } } diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index da2c0d8c..f27a4b8a 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -35,7 +35,7 @@ struct Layer<'a> { } impl<'a> Layer<'a> { - pub const fn new(bounds: Rectangle, offset: Vector) -> Self { + pub fn new(bounds: Rectangle, offset: Vector) -> Self { Self { bounds, offset,