Skip to content

Commit 03faba0

Browse files
committed
chore: style ...
1 parent 5f2686f commit 03faba0

File tree

23 files changed

+189
-149
lines changed

23 files changed

+189
-149
lines changed

day_01/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
pub mod part_01;
22
pub mod part_02;
33

4-
pub fn parse_input(string: &str) -> Vec<u32> {
4+
pub type Input = Vec<u32>;
5+
6+
pub fn parse_input(string: &str) -> Input {
57
string
68
.lines()
7-
.map(|string| string.trim())
9+
.map(str::trim)
810
.filter(|string| !string.is_empty())
911
.into_iter()
1012
.map(|string| string.parse::<u32>().unwrap())

day_01/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use day_01::{parse_input, part_01::main as part_01, part_02::main as part_02};
55
fn main() -> Result<()> {
66
let input = parse_input(include_str!("../../input/day_01"));
77

8-
println!("part_01: {:?}", part_01(&input).unwrap());
9-
println!("part_02: {:?}", part_02(&input).unwrap());
8+
println!("part_01: {:?}", part_01(&input)?);
9+
println!("part_02: {:?}", part_02(&input)?);
1010

1111
Ok(())
1212
}

day_01/src/part_01.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::io::Result;
22

3-
pub fn main(input: &Vec<u32>) -> Result<u32> {
3+
use crate::Input;
4+
5+
pub fn main(input: &Input) -> Result<u32> {
46
let mut entries = (0, 0);
57
'outer: for a in input {
68
for b in input.into_iter() {
@@ -16,9 +18,10 @@ pub fn main(input: &Vec<u32>) -> Result<u32> {
1618

1719
#[cfg(test)]
1820
mod tests {
19-
use super::*;
2021
use crate::parse_input;
2122

23+
use super::*;
24+
2225
const EXAMPLE_DATA: &'static str = "
2326
1721
2427
979
@@ -29,7 +32,8 @@ mod tests {
2932
";
3033

3134
#[test]
32-
fn it_gets_the_example_correct() {
33-
assert_eq!(main(&parse_input(EXAMPLE_DATA)).unwrap(), 514579)
35+
fn it_gets_the_example_correct() -> Result<()> {
36+
assert_eq!(main(&parse_input(EXAMPLE_DATA))?, 514579);
37+
Ok(())
3438
}
3539
}

day_01/src/part_02.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::io::Result;
22

3-
pub fn main(input: &Vec<u32>) -> Result<u32> {
3+
use crate::Input;
4+
5+
pub fn main(input: &Input) -> Result<u32> {
46
let mut entries = (0, 0, 0);
57
'outer: for a in input {
68
for b in input.into_iter() {
@@ -18,9 +20,10 @@ pub fn main(input: &Vec<u32>) -> Result<u32> {
1820

1921
#[cfg(test)]
2022
mod tests {
21-
use super::*;
2223
use crate::parse_input;
2324

25+
use super::*;
26+
2427
const EXAMPLE_DATA: &'static str = "
2528
1721
2629
979
@@ -31,7 +34,8 @@ mod tests {
3134
";
3235

3336
#[test]
34-
fn it_gets_the_example_correct() {
35-
assert_eq!(main(&parse_input(EXAMPLE_DATA)).unwrap(), 241861950)
37+
fn it_gets_the_example_correct() -> Result<()> {
38+
assert_eq!(main(&parse_input(EXAMPLE_DATA))?, 241861950);
39+
Ok(())
3640
}
3741
}

day_02/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pub mod part_01;
22
pub mod part_02;
33

4-
pub type Line = (u16, u16, char, String);
4+
pub type Input = Vec<(u16, u16, char, String)>;
55

6-
pub fn parse_input(input: &str) -> Vec<Line> {
6+
pub fn parse_input(input: &str) -> Input {
77
input
88
.lines()
99
.map(str::trim)

day_02/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use day_02::{parse_input, part_01::main as part_01, part_02::main as part_02};
55
fn main() -> Result<()> {
66
let input = parse_input(include_str!("../../input/day_02"));
77

8-
println!("part_01: {:?}", part_01(&input).unwrap());
9-
println!("part_02: {:?}", part_02(&input).unwrap());
8+
println!("part_01: {:?}", part_01(&input)?);
9+
println!("part_02: {:?}", part_02(&input)?);
1010

1111
Ok(())
1212
}

day_02/src/part_01.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io::Result;
22

3-
use crate::Line;
3+
use crate::Input;
44

5-
pub fn main(input: &Vec<Line>) -> Result<usize> {
5+
pub fn main(input: &Input) -> Result<usize> {
66
Ok(input
77
.into_iter()
88
.filter(|(min, max, char_to_match, password_string)| {
@@ -18,17 +18,19 @@ pub fn main(input: &Vec<Line>) -> Result<usize> {
1818

1919
#[cfg(test)]
2020
mod tests {
21-
use super::*;
2221
use crate::parse_input;
2322

23+
use super::*;
24+
2425
const EXAMPLE_DATA: &'static str = "
2526
1-3 a: abcde
2627
1-3 b: cdefg
2728
2-9 c: ccccccccc
2829
";
2930

3031
#[test]
31-
fn it_gets_the_example_correct() {
32-
assert_eq!(main(&parse_input(EXAMPLE_DATA)).unwrap(), 2)
32+
fn it_gets_the_example_correct() -> Result<()> {
33+
assert_eq!(main(&parse_input(EXAMPLE_DATA))?, 2);
34+
Ok(())
3335
}
3436
}

day_02/src/part_02.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io::Result;
22

3-
use crate::Line;
3+
use crate::Input;
44

5-
pub fn main(input: &Vec<Line>) -> Result<usize> {
5+
pub fn main(input: &Input) -> Result<usize> {
66
Ok(input
77
.into_iter()
88
.filter(
@@ -34,7 +34,8 @@ mod tests {
3434
";
3535

3636
#[test]
37-
fn it_gets_the_example_correct() {
38-
assert_eq!(main(&parse_input(EXAMPLE_DATA)).unwrap(), 1)
37+
fn it_gets_the_example_correct() -> Result<()> {
38+
assert_eq!(main(&parse_input(EXAMPLE_DATA))?, 1);
39+
Ok(())
3940
}
4041
}

day_03/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ pub enum Square {
99

1010
use Square::{Open, Tree};
1111

12-
pub fn parse_input(input: &str) -> Vec<Vec<Square>> {
12+
pub type Input = Vec<Vec<Square>>;
13+
14+
pub fn parse_input(input: &str) -> Input {
1315
input
1416
.lines()
15-
.map(|string| string.trim())
17+
.map(str::trim)
1618
.filter(|string| !string.is_empty())
1719
.into_iter()
1820
.map(|string| {

day_03/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use day_03::{parse_input, part_01::main as part_01, part_02::main as part_02};
55
fn main() -> Result<()> {
66
let input = parse_input(include_str!("../../input/day_03"));
77

8-
println!("part_01: {:?}", part_01(&input).unwrap());
9-
println!("part_02: {:?}", part_02(&input).unwrap());
8+
println!("part_01: {:?}", part_01(&input)?);
9+
println!("part_02: {:?}", part_02(&input)?);
1010

1111
Ok(())
1212
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy