diff options
author | 2019-11-29 21:24:52 -0500 | |
---|---|---|
committer | 2019-11-29 21:24:52 -0500 | |
commit | 267e242238fab0aba14fb4c2e27269ce3a3e3951 (patch) | |
tree | 6957be383f221ecc444ac50cdcbdfd45f6374349 /web/src/widget | |
parent | 811d8b90d71c26100f0933217f5474e090fbf17c (diff) | |
download | iced-267e242238fab0aba14fb4c2e27269ce3a3e3951.tar.gz iced-267e242238fab0aba14fb4c2e27269ce3a3e3951.tar.bz2 iced-267e242238fab0aba14fb4c2e27269ce3a3e3951.zip |
Make many functions `const`
The point is to set up repeated components or boilerplate before their
use sites.
The majority of these make sense as `const`. However, some functions
such as those regarding state may not make sense as `const`.
Diffstat (limited to 'web/src/widget')
-rw-r--r-- | web/src/widget/button.rs | 4 | ||||
-rw-r--r-- | web/src/widget/column.rs | 16 | ||||
-rw-r--r-- | web/src/widget/row.rs | 16 | ||||
-rw-r--r-- | web/src/widget/scrollable.rs | 4 | ||||
-rw-r--r-- | web/src/widget/slider.rs | 2 | ||||
-rw-r--r-- | web/src/widget/text_input.rs | 4 |
6 files changed, 23 insertions, 23 deletions
diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 889c0ab1..13b47077 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 fn new() -> State { - State::default() + pub const fn new() -> State { + State } } diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index cc850f5f..82b533dd 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 fn new() -> Self { + pub const 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 fn spacing(mut self, units: u16) -> Self { + pub const 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 fn padding(mut self, units: u16) -> Self { + pub const 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 fn width(mut self, width: Length) -> Self { + pub const 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 fn height(mut self, height: Length) -> Self { + pub const 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 fn max_width(mut self, max_width: u32) -> Self { + pub const 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 fn max_height(mut self, max_height: u32) -> Self { + pub const 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 fn align_items(mut self, align: Align) -> Self { + pub const 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 e47478be..0b4cec54 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 fn new() -> Self { + pub const 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 fn spacing(mut self, units: u16) -> Self { + pub const 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 fn padding(mut self, units: u16) -> Self { + pub const 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 fn width(mut self, width: Length) -> Self { + pub const 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 fn height(mut self, height: Length) -> Self { + pub const 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 fn max_width(mut self, max_width: u32) -> Self { + pub const 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 fn max_height(mut self, max_height: u32) -> Self { + pub const 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 fn align_items(mut self, align: Align) -> Self { + pub const 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 710bb70a..65766d74 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 fn new() -> Self { - State::default() + pub const fn new() -> Self { + State } } diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index 5b203e07..55848084 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 fn new() -> Self { + pub const fn new() -> Self { Self } } diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index d6357512..04c3b287 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 fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self } } |