Skip to content

Commit 11b452d

Browse files
authored
feat(layout): mark various functions as const (#951)
1 parent efd1e47 commit 11b452d

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::missing_const_for_fn)]
2+
13
mod alignment;
24
mod constraint;
35
mod corner;

src/layout/position.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Position {
3838

3939
impl Position {
4040
/// Create a new position
41-
pub fn new(x: u16, y: u16) -> Self {
41+
pub const fn new(x: u16, y: u16) -> Self {
4242
Position { x, y }
4343
}
4444
}

src/layout/rect.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl Rect {
245245
/// }
246246
/// }
247247
/// ```
248-
pub fn rows(self) -> Rows {
248+
pub const fn rows(self) -> Rows {
249249
Rows::new(self)
250250
}
251251

@@ -261,7 +261,7 @@ impl Rect {
261261
/// }
262262
/// }
263263
/// ```
264-
pub fn columns(self) -> Columns {
264+
pub const fn columns(self) -> Columns {
265265
Columns::new(self)
266266
}
267267

@@ -279,7 +279,7 @@ impl Rect {
279279
/// }
280280
/// }
281281
/// ```
282-
pub fn positions(self) -> Positions {
282+
pub const fn positions(self) -> Positions {
283283
Positions::new(self)
284284
}
285285

@@ -292,15 +292,15 @@ impl Rect {
292292
/// let rect = Rect::new(1, 2, 3, 4);
293293
/// let position = rect.as_position();
294294
/// ````
295-
pub fn as_position(self) -> Position {
295+
pub const fn as_position(self) -> Position {
296296
Position {
297297
x: self.x,
298298
y: self.y,
299299
}
300300
}
301301

302302
/// Converts the rect into a size struct.
303-
pub fn as_size(self) -> Size {
303+
pub const fn as_size(self) -> Size {
304304
Size {
305305
width: self.width,
306306
height: self.height,

src/layout/rect/iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Rows {
1111

1212
impl Rows {
1313
/// Creates a new `Rows` iterator.
14-
pub fn new(rect: Rect) -> Self {
14+
pub const fn new(rect: Rect) -> Self {
1515
Self {
1616
rect,
1717
current_row: rect.y,
@@ -45,7 +45,7 @@ pub struct Columns {
4545

4646
impl Columns {
4747
/// Creates a new `Columns` iterator.
48-
pub fn new(rect: Rect) -> Self {
48+
pub const fn new(rect: Rect) -> Self {
4949
Self {
5050
rect,
5151
current_column: rect.x,
@@ -81,7 +81,7 @@ pub struct Positions {
8181

8282
impl Positions {
8383
/// Creates a new `Positions` iterator.
84-
pub fn new(rect: Rect) -> Self {
84+
pub const fn new(rect: Rect) -> Self {
8585
Self {
8686
rect,
8787
current_position: Position::new(rect.x, rect.y),

src/layout/size.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Size {
1515

1616
impl Size {
1717
/// Create a new `Size` struct
18-
pub fn new(width: u16, height: u16) -> Self {
18+
pub const fn new(width: u16, height: u16) -> Self {
1919
Size { width, height }
2020
}
2121
}

src/widgets/canvas/line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Line {
2020

2121
impl Line {
2222
/// Create a new line from `(x1, y1)` to `(x2, y2)` with the given color
23-
pub fn new(x1: f64, y1: f64, x2: f64, y2: f64, color: Color) -> Self {
23+
pub const fn new(x1: f64, y1: f64, x2: f64, y2: f64, color: Color) -> Self {
2424
Self {
2525
x1,
2626
y1,

0 commit comments

Comments
 (0)