Skip to content

Commit 20684c8

Browse files
committed
clippy nursery 🍼 (almost)
1 parent bb80b2e commit 20684c8

File tree

29 files changed

+136
-139
lines changed

29 files changed

+136
-139
lines changed

2018/day1/day1.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 {
10+
const fn new() -> Self {
11+
Self {
1212
data: String::new(),
1313
}
1414
}

2018/day10/day10.rs

Lines changed: 3 additions & 3 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 {
14+
const fn new() -> Self {
15+
Self {
1616
pos: vec![],
1717
vel: vec![],
1818
message: String::new(),
@@ -113,7 +113,7 @@ impl Puzzle {
113113
}
114114

115115
/// Solve part two.
116-
fn part2(&self) -> u32 {
116+
const fn part2(&self) -> u32 {
117117
self.seconds
118118
}
119119
}

2018/day11/day11.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 { serial_number: 0 }
8+
const fn new() -> Self {
9+
Self { serial_number: 0 }
1010
}
1111

1212
/// Get the puzzle input.

2018/day12/day12.rs

Lines changed: 5 additions & 5 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+
fn new() -> Self {
12+
Self {
1313
state: String::new(),
1414
rules: HashSet::new(),
1515
}
@@ -23,14 +23,14 @@ impl Puzzle {
2323
if let Some(state) = line.strip_prefix("initial state: ") {
2424
self.state = state.to_string();
2525
} else if let Some(from) = line.strip_suffix(" => #") {
26-
self.rules.insert(Vec::from_iter(from.chars()));
26+
self.rules.insert(from.chars().collect::<Vec<_>>());
2727
}
2828
}
2929
}
3030

3131
/// Solve part one.
3232
fn part1(&self) -> i32 {
33-
let mut state = Vec::from_iter(self.state.chars());
33+
let mut state = self.state.chars().collect::<Vec<_>>();
3434

3535
let mut pots = 0;
3636

@@ -76,7 +76,7 @@ impl Puzzle {
7676

7777
/// Solve part two.
7878
fn part2(&self) -> i64 {
79-
let mut state = Vec::from_iter(self.state.chars());
79+
let mut state = self.state.chars().collect::<Vec<_>>();
8080

8181
let mut score = 0;
8282
let mut pots = 0;

2018/day13/day13.rs

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

3434
impl Puzzle {
35-
fn new() -> Puzzle {
36-
Puzzle {
35+
fn new() -> Self {
36+
Self {
3737
verbose: false,
3838
grid: Grid::new(),
3939
carts: vec![],

2018/day14/day14.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn appear(recipes: &str) -> usize {
4848

4949
let score: Vec<u8> = recipes
5050
.chars()
51-
.map(|c| c.to_digit(10).unwrap() as u8)
51+
.map(|c| u8::try_from(c.to_digit(10).unwrap()).unwrap())
5252
.collect();
5353

5454
let score = score.as_slice();
@@ -85,8 +85,8 @@ struct Puzzle {
8585
}
8686

8787
impl Puzzle {
88-
fn new() -> Puzzle {
89-
Puzzle {
88+
const fn new() -> Self {
89+
Self {
9090
recipes: String::new(),
9191
}
9292
}
@@ -95,7 +95,7 @@ impl Puzzle {
9595
fn configure(&mut self, path: &str) {
9696
let data = std::fs::read_to_string(path).unwrap();
9797

98-
self.recipes = data.trim().to_owned();
98+
data.trim().clone_into(&mut self.recipes);
9999
}
100100

101101
/// Solve part one.

2018/day15/day15.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ fn next_pos(
100100
if target_adj.contains(&(x, y)) {
101101
min_path = min_path.min(steps);
102102
pos.push(e);
103-
} else if !visited.contains(&(x, y)) {
104-
visited.insert((x, y));
105-
103+
} else if visited.insert((x, y)) {
106104
q.extend(
107105
adjacent(x, y)
108106
.iter()
@@ -138,8 +136,8 @@ fn has_elves_and_goblins(units: &[Unit]) -> bool {
138136
}
139137

140138
impl Puzzle {
141-
fn new() -> Puzzle {
142-
Puzzle {
139+
fn new() -> Self {
140+
Self {
143141
wall: HashSet::new(),
144142
units: vec![],
145143
}

2018/day16/day16.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct Puzzle {
4040
}
4141

4242
impl Puzzle {
43-
fn new() -> Puzzle {
44-
Puzzle {
43+
const fn new() -> Self {
44+
Self {
4545
result1: 0,
4646
result2: 0,
4747
}
@@ -142,12 +142,12 @@ impl Puzzle {
142142
}
143143

144144
/// Solve part one.
145-
fn part1(&self) -> u32 {
145+
const fn part1(&self) -> u32 {
146146
self.result1
147147
}
148148

149149
/// Solve part two.
150-
fn part2(&self) -> u32 {
150+
const fn part2(&self) -> u32 {
151151
self.result2
152152
}
153153
}

2018/day17/day17.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ struct Point {
2121
}
2222

2323
impl Point {
24-
fn go(&self, dir: &Dir) -> Self {
24+
const fn go(&self, dir: &Dir) -> Self {
2525
match dir {
26-
Dir::Right => Point {
26+
Dir::Right => Self {
2727
x: self.x + 1,
2828
y: self.y,
2929
},
30-
Dir::Left => Point {
30+
Dir::Left => Self {
3131
x: self.x - 1,
3232
y: self.y,
3333
},
34-
Dir::Down => Point {
34+
Dir::Down => Self {
3535
x: self.x,
3636
y: self.y + 1,
3737
},
@@ -66,8 +66,8 @@ struct Puzzle {
6666
}
6767

6868
impl Puzzle {
69-
fn new() -> Puzzle {
70-
Puzzle {
69+
fn new() -> Self {
70+
Self {
7171
grid: HashMap::new(),
7272
ymin: 0,
7373
ymax: 0,
@@ -108,15 +108,15 @@ impl Puzzle {
108108

109109
for y in 0..=self.ymax {
110110
for x in xmin..=xmax {
111-
let c = match self.grid.get(&Point { x, y }) {
112-
Some(t) => match *t {
113-
CLAY => "\x1b[38;5;166m#\x1b[0m",
114-
SETTLE => "?",
115-
FLOW => "\x1b[94m|\x1b[0m",
116-
_ => "\x1b[96m~\x1b[0m",
117-
},
118-
_ => "\x1b[38;5;231m.\x1b[0m",
119-
};
111+
let c =
112+
self.grid
113+
.get(&Point { x, y })
114+
.map_or("\x1b[38;5;231m.\x1b[0m", |t| match *t {
115+
CLAY => "\x1b[38;5;166m#\x1b[0m",
116+
SETTLE => "?",
117+
FLOW => "\x1b[94m|\x1b[0m",
118+
_ => "\x1b[96m~\x1b[0m",
119+
});
120120
print!("{c}");
121121
}
122122
println!();

2018/day18/day18.rs

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

9090
impl Puzzle {
91-
fn new() -> Puzzle {
92-
Puzzle {
91+
fn new() -> Self {
92+
Self {
9393
area: grid![],
9494
n: 0,
9595
}

0 commit comments

Comments
 (0)