Skip to content

Commit 235f240

Browse files
committedJan 1, 2025·
Rust 2024 Edition formatting
1 parent 59828aa commit 235f240

File tree

22 files changed

+27
-88
lines changed

22 files changed

+27
-88
lines changed
 

‎rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
style_edition = "2024"
12
use_small_heuristics = "Max"

‎src/year2016/day05.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//! [`Year 2015 Day 4`]: crate::year2015::day04
77
use crate::util::md5::*;
88
use crate::util::thread::*;
9-
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
109
use std::sync::Mutex;
10+
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
1111

1212
struct Shared {
1313
prefix: String,

‎src/year2016/day07.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ pub fn part1(input: &[u8]) -> usize {
3838
}
3939
}
4040

41-
if positive && !negative {
42-
count + 1
43-
} else {
44-
count
45-
}
41+
if positive && !negative { count + 1 } else { count }
4642
}
4743

4844
pub fn part2(input: &[u8]) -> usize {
@@ -84,9 +80,5 @@ pub fn part2(input: &[u8]) -> usize {
8480
}
8581
}
8682

87-
if positive {
88-
count + 1
89-
} else {
90-
count
91-
}
83+
if positive { count + 1 } else { count }
9284
}

‎src/year2016/day14.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use crate::util::md5::*;
66
use crate::util::thread::*;
77
use std::collections::{BTreeMap, BTreeSet};
8-
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
98
use std::sync::Mutex;
9+
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
1010

1111
/// Atomics can be safely shared between threads.
1212
struct Shared<'a> {

‎src/year2017/day14.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//! [`Day 10`]: crate::year2017::day10
77
//! [`Day 12`]: crate::year2017::day12
88
use crate::util::thread::*;
9-
use std::sync::atomic::{AtomicUsize, Ordering};
109
use std::sync::Mutex;
10+
use std::sync::atomic::{AtomicUsize, Ordering};
1111

1212
/// Atomics can be safely shared between threads.
1313
pub struct Shared {

‎src/year2017/day15.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::util::iter::*;
1111
use crate::util::math::*;
1212
use crate::util::parse::*;
1313
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
14-
use std::sync::mpsc::{channel, Receiver, Sender};
14+
use std::sync::mpsc::{Receiver, Sender, channel};
1515
use std::thread;
1616

1717
const PART_ONE: usize = 40_000_000;

‎src/year2018/day14.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! * Vector processing of recipes using techniques similar to SIMD.
1313
use crate::util::parse::*;
1414
use std::sync::atomic::{AtomicBool, Ordering};
15-
use std::sync::mpsc::{channel, Receiver, Sender};
15+
use std::sync::mpsc::{Receiver, Sender, channel};
1616
use std::thread;
1717

1818
type Input = (String, usize);

‎src/year2018/day15.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use crate::util::grid::*;
8080
use crate::util::point::*;
8181
use crate::util::thread::*;
8282
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
83-
use std::sync::mpsc::{channel, Sender};
83+
use std::sync::mpsc::{Sender, channel};
8484

8585
const READING_ORDER: [Point; 4] = [UP, LEFT, RIGHT, DOWN];
8686

‎src/year2018/day19.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,5 @@ fn divisor_sum(mut n: u32) -> u32 {
114114
// If `n` is one then the greatest prime factor was repeated so has already been included in
115115
// the sum and we can just return it directly. Otherwise `n` is the unique greatest prime
116116
// factor and must be added to the sum.
117-
if n == 1 {
118-
sum
119-
} else {
120-
sum * (1 + n)
121-
}
117+
if n == 1 { sum } else { sum * (1 + n) }
122118
}

‎src/year2018/day24.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::util::hash::*;
1111
use crate::util::parse::*;
1212
use crate::util::thread::*;
1313
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
14-
use std::sync::mpsc::{channel, Sender};
14+
use std::sync::mpsc::{Sender, channel};
1515

1616
pub struct Input {
1717
immune: Vec<Group>,

‎src/year2019/day06.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
pub fn parse(input: &str) -> Vec<usize> {
1414
// Convert 'A'.."Z" and '0'..'9' to a number between 0 and 36.
1515
let digit = |b: u8| {
16-
if b.is_ascii_digit() {
17-
(b - b'0') as usize
18-
} else {
19-
(10 + b - b'A') as usize
20-
}
16+
if b.is_ascii_digit() { (b - b'0') as usize } else { (10 + b - b'A') as usize }
2117
};
2218

2319
// Hash each 3 character object name.

‎src/year2019/day12.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ type Input = [Axis; 3];
2323
/// Group each axis together
2424
pub fn parse(input: &str) -> Input {
2525
let n: Vec<_> = input.iter_signed().collect();
26-
[
27-
[n[0], n[3], n[6], n[9], 0, 0, 0, 0],
28-
[n[1], n[4], n[7], n[10], 0, 0, 0, 0],
29-
[n[2], n[5], n[8], n[11], 0, 0, 0, 0],
30-
]
26+
[[n[0], n[3], n[6], n[9], 0, 0, 0, 0], [n[1], n[4], n[7], n[10], 0, 0, 0, 0], [
27+
n[2], n[5], n[8], n[11], 0, 0, 0, 0,
28+
]]
3129
}
3230

3331
pub fn part1(input: &Input) -> i32 {

‎src/year2019/day25.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ pub fn parse(input: &str) -> Vec<i64> {
2626
}
2727

2828
pub fn part1(input: &[i64]) -> String {
29-
if cfg!(feature = "frivolity") {
30-
play_manually(input)
31-
} else {
32-
play_automatically(input)
33-
}
29+
if cfg!(feature = "frivolity") { play_manually(input) } else { play_automatically(input) }
3430
}
3531

3632
pub fn part2(_input: &[i64]) -> &'static str {

‎src/year2020/day22.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ pub fn part1(input: &Input) -> usize {
151151
}
152152
}
153153

154-
if deck1.non_empty() {
155-
deck1.score
156-
} else {
157-
deck2.score
158-
}
154+
if deck1.non_empty() { deck1.score } else { deck2.score }
159155
}
160156

161157
pub fn part2(input: &Input) -> usize {
@@ -210,9 +206,5 @@ fn combat(deck1: &mut Deck, deck2: &mut Deck, cache: &mut Cache, depth: usize) -
210206
}
211207
}
212208

213-
if deck1.non_empty() {
214-
Winner::Player1
215-
} else {
216-
Winner::Player2
217-
}
209+
if deck1.non_empty() { Winner::Player1 } else { Winner::Player2 }
218210
}

‎src/year2021/day07.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ fn median(input: &[i32]) -> i32 {
3737
let half = input.len() / 2;
3838
let odd = crabs.len() % 2 == 1;
3939

40-
if odd {
41-
crabs[half]
42-
} else {
43-
(crabs[half - 1] + crabs[half]) / 2
44-
}
40+
if odd { crabs[half] } else { (crabs[half - 1] + crabs[half]) / 2 }
4541
}
4642

4743
fn mean(input: &[i32]) -> i32 {

‎src/year2021/day13.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,11 @@ pub fn part2(input: &Input) -> String {
100100
/// Fold point at `x` coordinate, doing nothing if the point is to the left of the fold line.
101101
#[inline]
102102
fn fold_horizontal(x: i32, p: Point) -> Point {
103-
if p.x < x {
104-
p
105-
} else {
106-
Point::new(2 * x - p.x, p.y)
107-
}
103+
if p.x < x { p } else { Point::new(2 * x - p.x, p.y) }
108104
}
109105

110106
/// Fold point at `y` coordinate, doing nothing if the point is above the fold line.
111107
#[inline]
112108
fn fold_vertical(y: i32, p: Point) -> Point {
113-
if p.y < y {
114-
p
115-
} else {
116-
Point::new(p.x, 2 * y - p.y)
117-
}
109+
if p.y < y { p } else { Point::new(p.x, 2 * y - p.y) }
118110
}

‎src/year2021/day16.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ impl BitStream<'_> {
4242
fn hex_to_binary(&mut self) -> u64 {
4343
let hex_digit = self.iter.next().unwrap();
4444

45-
if hex_digit.is_ascii_digit() {
46-
(hex_digit - 48) as u64
47-
} else {
48-
(hex_digit - 55) as u64
49-
}
45+
if hex_digit.is_ascii_digit() { (hex_digit - 48) as u64 } else { (hex_digit - 55) as u64 }
5046
}
5147
}
5248

‎src/year2022/day10.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ pub fn part1(input: &[i32]) -> i32 {
2727
/// Returns pixels as a multi-line [`String`] so that the entire function can be integration tested.
2828
pub fn part2(input: &[i32]) -> String {
2929
let to_char = |(i, c): (usize, &i32)| {
30-
if ((i as i32) - c).abs() <= 1 {
31-
'#'
32-
} else {
33-
'.'
34-
}
30+
if ((i as i32) - c).abs() <= 1 { '#' } else { '.' }
3531
};
3632
let mut result = input
3733
.chunks_exact(40)

‎src/year2022/day13.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ pub fn part1(input: &[&str]) -> usize {
4141
.enumerate()
4242
.map(|(i, chunk)| {
4343
let ordered = compare(chunk[0], chunk[1]);
44-
if ordered {
45-
i + 1
46-
} else {
47-
0
48-
}
44+
if ordered { i + 1 } else { 0 }
4945
})
5046
.sum()
5147
}

‎src/year2023/day16.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::util::grid::*;
1515
use crate::util::point::*;
1616
use crate::util::thread::*;
1717
use std::collections::VecDeque;
18-
use std::sync::atomic::{AtomicUsize, Ordering};
1918
use std::sync::Mutex;
19+
use std::sync::atomic::{AtomicUsize, Ordering};
2020

2121
type Pair = (Point, u32);
2222

‎src/year2024/day02.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,5 @@ fn check(report: &[i32]) -> (u32, u32) {
7777
fn delta(a: i32, b: i32) -> i32 {
7878
let diff = b - a;
7979

80-
if diff.abs() <= 3 {
81-
diff.signum()
82-
} else {
83-
0
84-
}
80+
if diff.abs() <= 3 { diff.signum() } else { 0 }
8581
}

‎src/year2024/day13.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,5 @@ fn play(&[ax, ay, bx, by, mut px, mut py]: &Claw, part_two: bool) -> i64 {
5656
a /= det;
5757
b /= det;
5858

59-
if part_two || (a <= 100 && b <= 100) {
60-
3 * a + b
61-
} else {
62-
0
63-
}
59+
if part_two || (a <= 100 && b <= 100) { 3 * a + b } else { 0 }
6460
}

0 commit comments

Comments
 (0)