fix some pedantic clippy lints that make sense
- clippy::redundant-closure-for-method-calls - clippy::explicit-iter-loop
This commit is contained in:
parent
449cdc0157
commit
e25bc47f8f
20 changed files with 59 additions and 66 deletions
|
|
@ -92,7 +92,7 @@ pub fn run() -> Result<String> {
|
|||
fn part1(input: &str) -> Result<usize> {
|
||||
let policies = input
|
||||
.lines()
|
||||
.map(|line| line.parse::<PassPolicy>())
|
||||
.map(str::parse::<PassPolicy>)
|
||||
.collect::<Result<Vec<PassPolicy>>>()?;
|
||||
|
||||
Ok(policies
|
||||
|
|
@ -104,7 +104,7 @@ fn part1(input: &str) -> Result<usize> {
|
|||
fn part2(input: &str) -> Result<usize> {
|
||||
let policies = input
|
||||
.lines()
|
||||
.map(|line| line.parse::<PassPolicy>())
|
||||
.map(str::parse::<PassPolicy>)
|
||||
.collect::<Result<Vec<PassPolicy>>>()?;
|
||||
|
||||
Ok(policies
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ fn part2(input: &str) -> Result<usize> {
|
|||
|
||||
Ok(passports
|
||||
.into_iter()
|
||||
.filter_map(|p| p.complete())
|
||||
.filter(|p| p.is_valid())
|
||||
.filter_map(Passport::complete)
|
||||
.filter(CompletePassport::is_valid)
|
||||
.count())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ pub fn run() -> Result<String> {
|
|||
fn part1(input: &str) -> Result<usize> {
|
||||
let seats = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<Seat>>>()?;
|
||||
|
||||
seats
|
||||
.iter()
|
||||
.map(|seat| seat.id())
|
||||
.map(Seat::id)
|
||||
.max()
|
||||
.context("0 seats processed")
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ fn part1(input: &str) -> Result<usize> {
|
|||
fn part2(input: &str) -> Result<usize> {
|
||||
let mut seats = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<Seat>>>()?;
|
||||
|
||||
// Seats will be sorted by lexicographical order of fields thanks to `derive(PartialOrd, Ord)`,
|
||||
|
|
@ -39,7 +39,7 @@ fn part2(input: &str) -> Result<usize> {
|
|||
seats.sort_unstable();
|
||||
|
||||
let mut prev_id = None;
|
||||
for id in seats.iter().map(|s| s.id()) {
|
||||
for id in seats.iter().map(Seat::id) {
|
||||
match prev_id {
|
||||
Some(pid) if pid == (id - 1) => prev_id = Some(id),
|
||||
Some(pid) => return Ok(pid + 1),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub fn run() -> Result<String> {
|
|||
fn part1(input: &str) -> Result<usize> {
|
||||
let bag_rules = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<BagRule>>>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ fn part1(input: &str) -> Result<usize> {
|
|||
fn part2(input: &str) -> Result<usize> {
|
||||
let bag_rules = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<BagRule>>>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ mod tests {
|
|||
fn part1_provided_parse() {
|
||||
let bag_rules = PROVIDED1
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<BagRule>>>()
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub fn run() -> Result<String> {
|
|||
fn part1(input: &str) -> Result<i64> {
|
||||
let instructions = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<Instruction>>>()?;
|
||||
|
||||
let mut interpreter = Interpreter::new(instructions);
|
||||
|
|
@ -31,7 +31,7 @@ fn part1(input: &str) -> Result<i64> {
|
|||
fn part2(input: &str) -> Result<i64> {
|
||||
let instructions = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<Instruction>>>()?;
|
||||
|
||||
for idx in 0..instructions.len() {
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ pub fn run() -> Result<String> {
|
|||
}
|
||||
|
||||
fn part1(input: &str) -> Result<i64> {
|
||||
let actions: Vec<Action> = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.collect::<Result<_>>()?;
|
||||
let actions: Vec<Action> = input.lines().map(str::parse).collect::<Result<_>>()?;
|
||||
|
||||
let mut ship = Ship::new();
|
||||
|
||||
|
|
@ -29,10 +26,7 @@ fn part1(input: &str) -> Result<i64> {
|
|||
}
|
||||
|
||||
fn part2(input: &str) -> Result<i64> {
|
||||
let actions: Vec<Action> = input
|
||||
.lines()
|
||||
.map(|line| line.parse())
|
||||
.collect::<Result<_>>()?;
|
||||
let actions: Vec<Action> = input.lines().map(str::parse).collect::<Result<_>>()?;
|
||||
|
||||
let mut ship = Ship::new();
|
||||
|
||||
|
|
@ -212,7 +206,7 @@ impl Ship {
|
|||
}
|
||||
|
||||
ActionKind::Forward => {
|
||||
for mv in self.waypoint.as_moves(action.arg).iter() {
|
||||
for mv in &self.waypoint.as_moves(action.arg) {
|
||||
self.process(mv);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ impl std::str::FromStr for Program {
|
|||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
let instructions = s.lines().map(|line| line.parse()).collect::<Result<_>>()?;
|
||||
let instructions = s.lines().map(str::parse).collect::<Result<_>>()?;
|
||||
|
||||
Ok(Program {
|
||||
instructions,
|
||||
|
|
|
|||
|
|
@ -120,13 +120,13 @@ fn parse_input(input: &str) -> Result<(HashMap<&str, Field>, Ticket, Vec<Ticket>
|
|||
let my_ticket = my_ticket_part
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.next()
|
||||
.context("no second line for ticket")??;
|
||||
let tickets = tickets_part
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(|line| line.parse())
|
||||
.map(str::parse)
|
||||
.collect::<Result<_>>()
|
||||
.context("couldn't parse tickets")?;
|
||||
|
||||
|
|
@ -184,16 +184,19 @@ impl std::str::FromStr for Field {
|
|||
fn from_str(s: &str) -> Result<Self> {
|
||||
let mut ranges = s.split(" or ");
|
||||
|
||||
let mut range1 = ranges.next().context("no first range found")?.split('-');
|
||||
let range1_start = range1.next().context("no bound for range")?.parse()?;
|
||||
let range1_end = range1.next().context("no bound for range")?.parse()?;
|
||||
let mut first_range = ranges.next().context("no first range found")?.split('-');
|
||||
let first_range_start = first_range.next().context("no bound for range")?.parse()?;
|
||||
let first_range_end = first_range.next().context("no bound for range")?.parse()?;
|
||||
|
||||
let mut range2 = ranges.next().context("no second range found")?.split('-');
|
||||
let range2_start = range2.next().context("no bound for range")?.parse()?;
|
||||
let range2_end = range2.next().context("no bound for range")?.parse()?;
|
||||
let mut second_range = ranges.next().context("no second range found")?.split('-');
|
||||
let second_range_start = second_range.next().context("no bound for range")?.parse()?;
|
||||
let second_range_end = second_range.next().context("no bound for range")?.parse()?;
|
||||
|
||||
Ok(Field {
|
||||
ranges: (range1_start..=range1_end, range2_start..=range2_end),
|
||||
ranges: (
|
||||
first_range_start..=first_range_end,
|
||||
second_range_start..=second_range_end,
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue