Skip to content

Commit b42d4e1

Browse files
committed
clippy nursery 🍼
1 parent 708070f commit b42d4e1

File tree

25 files changed

+73
-75
lines changed

25 files changed

+73
-75
lines changed

2024/aoc24/src/coord.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ pub struct Coord {
99
}
1010

1111
impl Coord {
12-
pub const LEFT: Coord = Coord { x: -1, y: 0 };
13-
pub const RIGHT: Coord = Coord { x: 1, y: 0 };
14-
pub const UP: Coord = Coord { x: 0, y: -1 };
15-
pub const DOWN: Coord = Coord { x: 0, y: 1 };
12+
pub const LEFT: Self = Self { x: -1, y: 0 };
13+
pub const RIGHT: Self = Self { x: 1, y: 0 };
14+
pub const UP: Self = Self { x: 0, y: -1 };
15+
pub const DOWN: Self = Self { x: 0, y: 1 };
1616
}
1717

1818
impl Coord {
1919
#[must_use]
20-
pub fn new(x: i32, y: i32) -> Self {
20+
pub const fn new(x: i32, y: i32) -> Self {
2121
Self { x, y }
2222
}
2323

2424
#[must_use]
25-
pub fn manhattan_distance(&self, rhs: &Coord) -> i32 {
25+
pub const fn manhattan_distance(&self, rhs: &Self) -> i32 {
2626
(self.x - rhs.x).abs() + (self.y - rhs.y).abs()
2727
}
2828
}
2929

3030
impl Add for Coord {
31-
type Output = Coord;
32-
fn add(self, rhs: Coord) -> Coord {
33-
Coord {
31+
type Output = Self;
32+
fn add(self, rhs: Self) -> Self {
33+
Self {
3434
x: self.x + rhs.x,
3535
y: self.y + rhs.y,
3636
}
@@ -45,9 +45,9 @@ impl AddAssign for Coord {
4545
}
4646

4747
impl Sub for Coord {
48-
type Output = Coord;
49-
fn sub(self, rhs: Coord) -> Coord {
50-
Coord {
48+
type Output = Self;
49+
fn sub(self, rhs: Self) -> Self {
50+
Self {
5151
x: self.x - rhs.x,
5252
y: self.y - rhs.y,
5353
}
@@ -62,10 +62,10 @@ impl SubAssign for Coord {
6262
}
6363

6464
impl Mul<i32> for Coord {
65-
type Output = Coord;
65+
type Output = Self;
6666

67-
fn mul(self, rhs: i32) -> Coord {
68-
Coord {
67+
fn mul(self, rhs: i32) -> Self {
68+
Self {
6969
x: self.x * rhs,
7070
y: self.y * rhs,
7171
}

2024/aoc24/src/grid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ impl Grid {
3333
}
3434

3535
#[must_use]
36-
pub fn width(&self) -> i32 {
36+
pub const fn width(&self) -> i32 {
3737
self.size.x
3838
}
3939

4040
#[must_use]
41-
pub fn height(&self) -> i32 {
41+
pub const fn height(&self) -> i32 {
4242
self.size.y
4343
}
4444

2024/day1/day1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ struct Puzzle {
88
}
99

1010
impl Puzzle {
11-
fn new() -> Puzzle {
12-
Puzzle {
11+
const fn new() -> Self {
12+
Self {
1313
left: vec![],
1414
right: vec![],
1515
}

2024/day10/day10.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ struct Puzzle {
1111
}
1212

1313
impl Puzzle {
14-
fn new() -> Puzzle {
15-
Puzzle { grid: grid![] }
14+
fn new() -> Self {
15+
Self { grid: grid![] }
1616
}
1717

1818
/// Get the puzzle input.

2024/day11/day11.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ struct Puzzle {
77
}
88

99
impl Puzzle {
10-
fn new() -> Puzzle {
11-
Puzzle { stones: Vec::new() }
10+
const fn new() -> Self {
11+
Self { stones: Vec::new() }
1212
}
1313

1414
/// Get the puzzle input.

2024/day12/day12.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct Puzzle {
99
}
1010

1111
impl Puzzle {
12-
fn new() -> Puzzle {
13-
Puzzle {
12+
const fn new() -> Self {
13+
Self {
1414
standard_price: 0,
1515
discount_price: 0,
1616
}
@@ -98,12 +98,12 @@ impl Puzzle {
9898
}
9999

100100
/// Solve part one.
101-
fn part1(&self) -> u32 {
101+
const fn part1(&self) -> u32 {
102102
self.standard_price
103103
}
104104

105105
/// Solve part two.
106-
fn part2(&self) -> u32 {
106+
const fn part2(&self) -> u32 {
107107
self.discount_price
108108
}
109109
}

2024/day13/day13.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct Puzzle {
5454
}
5555

5656
impl Puzzle {
57-
fn new() -> Puzzle {
58-
Puzzle { machines: vec![] }
57+
const fn new() -> Self {
58+
Self { machines: vec![] }
5959
}
6060

6161
/// Get the puzzle input.

2024/day13_z3/day13.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ struct Puzzle {
6767
}
6868

6969
impl Puzzle {
70-
fn new() -> Puzzle {
71-
Puzzle { machines: vec![] }
70+
const fn new() -> Self {
71+
Self { machines: vec![] }
7272
}
7373

7474
/// Get the puzzle input.

2024/day14/day14.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ struct Puzzle {
1717
}
1818

1919
impl Puzzle {
20-
fn new() -> Puzzle {
21-
Puzzle {
20+
const fn new() -> Self {
21+
Self {
2222
robots: Vec::new(),
2323
width: 101,
2424
height: 103,

2024/day15/day15.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ struct Puzzle {
187187
}
188188

189189
impl Puzzle {
190-
fn new() -> Puzzle {
191-
Puzzle {
190+
const fn new() -> Self {
191+
Self {
192192
data: String::new(),
193193
moves: vec![],
194194
anim: 0,
@@ -212,7 +212,7 @@ impl Puzzle {
212212
}
213213

214214
/// Solve part one.
215-
fn part1(&mut self) -> i32 {
215+
fn part1(&self) -> i32 {
216216
let (mut grid, mut robot) = init_first_warehouse(&self.data);
217217
let mut n = 1;
218218

0 commit comments

Comments
 (0)