Skip to content

Commit

Permalink
feat(layout): mark various functions as const (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo authored Feb 14, 2024
1 parent efd1e47 commit 11b452d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::missing_const_for_fn)]

mod alignment;
mod constraint;
mod corner;
Expand Down
2 changes: 1 addition & 1 deletion src/layout/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Position {

impl Position {
/// Create a new position
pub fn new(x: u16, y: u16) -> Self {
pub const fn new(x: u16, y: u16) -> Self {
Position { x, y }
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/layout/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Rect {
/// }
/// }
/// ```
pub fn rows(self) -> Rows {
pub const fn rows(self) -> Rows {
Rows::new(self)
}

Expand All @@ -261,7 +261,7 @@ impl Rect {
/// }
/// }
/// ```
pub fn columns(self) -> Columns {
pub const fn columns(self) -> Columns {
Columns::new(self)
}

Expand All @@ -279,7 +279,7 @@ impl Rect {
/// }
/// }
/// ```
pub fn positions(self) -> Positions {
pub const fn positions(self) -> Positions {
Positions::new(self)
}

Expand All @@ -292,15 +292,15 @@ impl Rect {
/// let rect = Rect::new(1, 2, 3, 4);
/// let position = rect.as_position();
/// ````
pub fn as_position(self) -> Position {
pub const fn as_position(self) -> Position {
Position {
x: self.x,
y: self.y,
}
}

/// Converts the rect into a size struct.
pub fn as_size(self) -> Size {
pub const fn as_size(self) -> Size {
Size {
width: self.width,
height: self.height,
Expand Down
6 changes: 3 additions & 3 deletions src/layout/rect/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Rows {

impl Rows {
/// Creates a new `Rows` iterator.
pub fn new(rect: Rect) -> Self {
pub const fn new(rect: Rect) -> Self {
Self {
rect,
current_row: rect.y,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct Columns {

impl Columns {
/// Creates a new `Columns` iterator.
pub fn new(rect: Rect) -> Self {
pub const fn new(rect: Rect) -> Self {
Self {
rect,
current_column: rect.x,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct Positions {

impl Positions {
/// Creates a new `Positions` iterator.
pub fn new(rect: Rect) -> Self {
pub const fn new(rect: Rect) -> Self {
Self {
rect,
current_position: Position::new(rect.x, rect.y),
Expand Down
2 changes: 1 addition & 1 deletion src/layout/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Size {

impl Size {
/// Create a new `Size` struct
pub fn new(width: u16, height: u16) -> Self {
pub const fn new(width: u16, height: u16) -> Self {
Size { width, height }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Line {

impl Line {
/// Create a new line from `(x1, y1)` to `(x2, y2)` with the given color
pub fn new(x1: f64, y1: f64, x2: f64, y2: f64, color: Color) -> Self {
pub const fn new(x1: f64, y1: f64, x2: f64, y2: f64, color: Color) -> Self {
Self {
x1,
y1,
Expand Down

0 comments on commit 11b452d

Please sign in to comment.