Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(layout): const functions #951

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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