Skip to content

Commit

Permalink
fix(style): make some functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Dec 27, 2024
1 parent 182864d commit a0f06f0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions benches/algos-fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Pt {
}

impl Pt {
fn new(x: u16, y: u16) -> Pt {
const fn new(x: u16, y: u16) -> Pt {
Pt {
x,
y,
Expand All @@ -21,7 +21,7 @@ impl Pt {
}

#[inline]
fn heuristic(p: &Pt) -> usize {
const fn heuristic(p: &Pt) -> usize {
(64 - p.x - p.y) as usize
}
}
Expand Down
4 changes: 2 additions & 2 deletions benches/algos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ struct Pt {
}

impl Pt {
fn new(x: u16, y: u16) -> Pt {
const fn new(x: u16, y: u16) -> Pt {
Pt { x, y }
}

#[inline]
fn heuristic(p: &Pt) -> usize {
const fn heuristic(p: &Pt) -> usize {
(128 - p.x - p.y) as usize
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/sliding-puzzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ impl Game {
}

#[inline]
fn x(pos: u8) -> u8 {
const fn x(pos: u8) -> u8 {
pos % SIDE
}

#[inline]
fn y(pos: u8) -> u8 {
const fn y(pos: u8) -> u8 {
pos / SIDE
}

Expand Down
6 changes: 3 additions & 3 deletions src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Grid {
/// is located outside the grid.
#[inline]
#[must_use]
pub fn is_inside(&self, vertex: (usize, usize)) -> bool {
pub const fn is_inside(&self, vertex: (usize, usize)) -> bool {
vertex.0 < self.width && vertex.1 < self.height
}

Expand Down Expand Up @@ -167,7 +167,7 @@ impl Grid {

/// Return the number of positions in this grid.
#[must_use]
pub fn size(&self) -> usize {
pub const fn size(&self) -> usize {
self.width * self.height
}

Expand Down Expand Up @@ -333,7 +333,7 @@ impl Grid {

/// Iterate over edges.
#[must_use]
pub fn edges(&self) -> EdgesIterator {
pub const fn edges(&self) -> EdgesIterator {
EdgesIterator {
grid: self,
x: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl<C> Matrix<C> {
/// requires building vectors of column data which are not stored
/// consecutively in memory.
#[must_use]
pub fn column_iter(&self) -> ColumnIterator<'_, C> {
pub const fn column_iter(&self) -> ColumnIterator<'_, C> {
ColumnIterator {
matrix: self,
column: 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod ex2 {
.collect()
}

fn distance(&(x1, y1): &(usize, usize), &(x2, y2): &(usize, usize)) -> usize {
const fn distance(&(x1, y1): &(usize, usize), &(x2, y2): &(usize, usize)) -> usize {
x1.abs_diff(x2) + y1.abs_diff(y2)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/r299.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn parse(input: &str) -> (Vec<Point>, HashMap<Point, SuccessorInfo>) {
(nodes, successors)
}

fn distance(a: &Point, b: &Point) -> usize {
const fn distance(a: &Point, b: &Point) -> usize {
a.row.abs_diff(b.row) + a.col.abs_diff(b.col)
}

Expand Down

0 comments on commit a0f06f0

Please sign in to comment.