Skip to content

Commit d367952

Browse files
committed
chore: make some functions const
1 parent ce1da0e commit d367952

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ version_check = "0.9.5"
4747
module_name_repetitions = { level = "allow", priority = 1 }
4848
too_long_first_doc_paragraph = { level = "allow", priority = 1 } # Temporary
4949
pedantic = "deny"
50+
missing_const_for_fn = "deny"
5051
# Do not activate until Clippy issue #13356 is fixed
5152
#allow_attributes = "deny"
5253

examples/sliding-puzzle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Game {
7575
}
7676

7777
// Compute the Manhattan distance between the piece at idx and its correct position.
78-
fn distance(&self, idx: u8) -> u8 {
78+
const fn distance(&self, idx: u8) -> u8 {
7979
let (actual_x, actual_y) = (Self::x(idx), Self::y(idx));
8080
let (correct_x, correct_y) = (
8181
Self::x(self.positions[idx as usize]),

src/grid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ impl Grid {
124124

125125
/// Enable diagonal mode. Diagonal edges will be created between
126126
/// adjacent vertices.
127-
pub fn enable_diagonal_mode(&mut self) {
127+
pub const fn enable_diagonal_mode(&mut self) {
128128
self.diagonal_mode = true;
129129
}
130130

131131
/// Disable diagonal mode. Only horizontal and vertical edges will
132132
/// be created between adjacent vertices.
133-
pub fn disable_diagonal_mode(&mut self) {
133+
pub const fn disable_diagonal_mode(&mut self) {
134134
self.diagonal_mode = false;
135135
}
136136

@@ -310,7 +310,7 @@ impl Grid {
310310
/// Remove every existing vertex, and add all absent vertices.
311311
/// If you see the grid as a black and white array, imagine that
312312
/// the color are exchanged.
313-
pub fn invert(&mut self) {
313+
pub const fn invert(&mut self) {
314314
self.dense = !self.dense;
315315
}
316316

0 commit comments

Comments
 (0)