Skip to content

Commit 6ec2e7d

Browse files
committed
clippy nursery 🍼 (many)
1 parent 1486757 commit 6ec2e7d

File tree

22 files changed

+91
-94
lines changed

22 files changed

+91
-94
lines changed

2022/day1/day1.rs

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

77
impl Puzzle {
8-
fn new() -> Puzzle {
9-
Puzzle {
8+
const fn new() -> Self {
9+
Self {
1010
calories: Vec::new(),
1111
}
1212
}

2022/day10/day10.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct Puzzle {
88
}
99

1010
impl Puzzle {
11-
fn new() -> Self {
11+
const fn new() -> Self {
1212
Self { cycles: vec![] }
1313
}
1414

2022/day11/day11.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ enum Operation {
1010
impl Operation {
1111
fn new(s: &str) -> Self {
1212
if s == "old * old" {
13-
return Operation::Square;
13+
return Self::Square;
1414
} else if let Some(m) = s.strip_prefix("old + ") {
15-
return Operation::Addition(m.parse().unwrap());
15+
return Self::Addition(m.parse().unwrap());
1616
} else if let Some(m) = s.strip_prefix("old * ") {
17-
return Operation::Product(m.parse().unwrap());
17+
return Self::Product(m.parse().unwrap());
1818
}
1919
panic!("bad operation {s}")
2020
}
2121

2222
fn calc(&self, arg: u64) -> u64 {
2323
match self {
24-
Operation::Square => arg * arg,
25-
Operation::Addition(n) => arg + n,
26-
Operation::Product(n) => arg * n,
24+
Self::Square => arg * arg,
25+
Self::Addition(n) => arg + n,
26+
Self::Product(n) => arg * n,
2727
}
2828
}
2929
}
@@ -43,7 +43,7 @@ struct Puzzle {
4343
}
4444

4545
impl Puzzle {
46-
fn new() -> Self {
46+
const fn new() -> Self {
4747
Self { monkeys: vec![] }
4848
}
4949

2022/day12/day12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Puzzle {
1717
}
1818

1919
impl Puzzle {
20-
fn new() -> Self {
20+
const fn new() -> Self {
2121
Self {
2222
grid: vec![],
2323
start: (0, 0),

2022/day13/day13.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct Puzzle {
7171
}
7272

7373
impl Puzzle {
74-
fn new() -> Self {
74+
const fn new() -> Self {
7575
Self { packets: vec![] }
7676
}
7777

@@ -118,6 +118,15 @@ impl Puzzle {
118118
}
119119
}
120120

121+
/// main function
122+
fn main() {
123+
let args = aoc::parse_args();
124+
let mut puzzle = Puzzle::new();
125+
puzzle.configure(&args.path);
126+
println!("{}", puzzle.part1());
127+
println!("{}", puzzle.part2());
128+
}
129+
121130
#[cfg(test)]
122131
mod test {
123132
use super::*;
@@ -130,12 +139,3 @@ mod test {
130139
assert_eq!(puzzle.part2(), 140);
131140
}
132141
}
133-
134-
/// main function
135-
fn main() {
136-
let args = aoc::parse_args();
137-
let mut puzzle = Puzzle::new();
138-
puzzle.configure(&args.path);
139-
println!("{}", puzzle.part1());
140-
println!("{}", puzzle.part2());
141-
}

2022/day13_nom/day13.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ impl Packet {
3030

3131
fn cmp(&self, other: &Self) -> Ordering {
3232
match (self, other) {
33-
(Packet::Integer(a), Packet::Integer(b)) => a.cmp(b),
34-
(Packet::Integer(_), Packet::Array(_)) => Packet::Array(vec![self.clone()]).cmp(other),
35-
(Packet::Array(_), Packet::Integer(_)) => self.cmp(&Packet::Array(vec![other.clone()])),
36-
(Packet::Array(a), Packet::Array(b)) => {
33+
(Self::Integer(a), Self::Integer(b)) => a.cmp(b),
34+
(Self::Integer(_), Self::Array(_)) => Self::Array(vec![self.clone()]).cmp(other),
35+
(Self::Array(_), Self::Integer(_)) => self.cmp(&Self::Array(vec![other.clone()])),
36+
(Self::Array(a), Self::Array(b)) => {
3737
let mut iter_a = a.iter();
3838
let mut iter_b = b.iter();
3939
loop {
@@ -58,7 +58,7 @@ struct Puzzle {
5858
}
5959

6060
impl Puzzle {
61-
fn new() -> Self {
61+
const fn new() -> Self {
6262
Self { packets: vec![] }
6363
}
6464

2022/day14/day14.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ impl Puzzle {
7777
if y + 1 >= self.floor {
7878
if part2 {
7979
break;
80-
} else {
81-
// sand is beyond the lowest rock
82-
return false;
8380
}
81+
82+
// sand is beyond the lowest rock
83+
return false;
8484
}
8585

8686
if self.is_empty(x, y + 1) {

2022/day15/day15.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use regex::Regex;
44
use std::collections::HashSet;
55

66
/// Computes the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between two points
7-
fn manhattan(ax: i64, ay: i64, bx: i64, by: i64) -> i64 {
7+
const fn manhattan(ax: i64, ay: i64, bx: i64, by: i64) -> i64 {
88
(ax - bx).abs() + (ay - by).abs()
99
}
1010

2022/day16/day16.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Puzzle {
2929
)
3030
.unwrap();
3131

32-
for line in data.split('\n').collect::<Vec<_>>() {
32+
for line in data.split('\n') {
3333
if let Some(m) = re.captures(line) {
3434
let valve = self.valve_id_new(&m[1]);
3535

@@ -57,7 +57,7 @@ impl Puzzle {
5757
}
5858
}
5959

60-
fn distance(&self, a: u8, b: u8) -> u32 {
60+
const fn distance(&self, a: u8, b: u8) -> u32 {
6161
self.distances[a as usize][b as usize]
6262
}
6363

2022/day19/day19.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ struct Puzzle {
208208
}
209209

210210
impl Puzzle {
211-
fn new() -> Self {
211+
const fn new() -> Self {
212212
Self { blueprints: vec![] }
213213
}
214214

0 commit comments

Comments
 (0)