mirror of
https://github.com/ratatui-org/ratatui
synced 2025-02-16 14:08:44 +00:00
feat(layout): mark various functions as const (#951)
This commit is contained in:
parent
efd1e47642
commit
11b452d56f
6 changed files with 13 additions and 11 deletions
|
@ -1,3 +1,5 @@
|
|||
#![warn(clippy::missing_const_for_fn)]
|
||||
|
||||
mod alignment;
|
||||
mod constraint;
|
||||
mod corner;
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ impl Rect {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn rows(self) -> Rows {
|
||||
pub const fn rows(self) -> Rows {
|
||||
Rows::new(self)
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ impl Rect {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn columns(self) -> Columns {
|
||||
pub const fn columns(self) -> Columns {
|
||||
Columns::new(self)
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ impl Rect {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn positions(self) -> Positions {
|
||||
pub const fn positions(self) -> Positions {
|
||||
Positions::new(self)
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ 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,
|
||||
|
@ -300,7 +300,7 @@ impl Rect {
|
|||
}
|
||||
|
||||
/// 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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue