From a77a039c70c70c697b3af3877163547868bfacd9 Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Tue, 8 Dec 2020 10:03:27 -0800 Subject: [PATCH] Small formatting wibbles. --- src/bin/accounting.rs | 2 +- src/bin/baggage.rs | 2 +- src/bin/boarding_pass.rs | 2 +- src/bin/customs_form.rs | 2 +- src/bin/machine.rs | 27 ++++++++++++++++++++------- src/bin/passport.rs | 2 +- src/bin/password_check.rs | 2 +- src/bin/tobaggan.rs | 2 +- src/errors.rs | 8 ++++---- 9 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/bin/accounting.rs b/src/bin/accounting.rs index 9bc83ae..d40bda0 100644 --- a/src/bin/accounting.rs +++ b/src/bin/accounting.rs @@ -118,4 +118,4 @@ fn next_target(low_index: usize, high_index: usize, avoid: &[usize]) -> Option Result<(), TopLevelError> { ); Ok(()) -} \ No newline at end of file +} diff --git a/src/bin/boarding_pass.rs b/src/bin/boarding_pass.rs index 242dfac..a58463b 100644 --- a/src/bin/boarding_pass.rs +++ b/src/bin/boarding_pass.rs @@ -147,4 +147,4 @@ fn main() -> Result<(), TopLevelError> { } Err(TopLevelError::NoSolutionFound) -} \ No newline at end of file +} diff --git a/src/bin/customs_form.rs b/src/bin/customs_form.rs index 5cf8a01..a5bad8e 100644 --- a/src/bin/customs_form.rs +++ b/src/bin/customs_form.rs @@ -73,4 +73,4 @@ fn every_seat() -> BTreeSet { } result -} \ No newline at end of file +} diff --git a/src/bin/machine.rs b/src/bin/machine.rs index ae2b4a2..1b38001 100644 --- a/src/bin/machine.rs +++ b/src/bin/machine.rs @@ -1,8 +1,8 @@ use advent2020::errors::{ExecutionError, InstructionParseError, TopLevelError}; -use std::{collections::HashSet, env}; use std::fmt; use std::fs; use std::str::FromStr; +use std::{collections::HashSet, env}; #[derive(Clone)] struct Machine { @@ -27,15 +27,21 @@ impl FromStr for Instruction { lowered.make_ascii_lowercase(); let mut items = s.split(' '); - let instruction = items.next().ok_or(InstructionParseError::EmptyInstruction)?; - let operand = items.next().ok_or(InstructionParseError::MissingOperand(instruction.to_string()))?; + let instruction = items + .next() + .ok_or(InstructionParseError::EmptyInstruction)?; + let operand = items.next().ok_or(InstructionParseError::MissingOperand( + instruction.to_string(), + ))?; let operand_value = isize::from_str(operand)?; match instruction { "nop" => Ok(Instruction::NOP(operand_value)), "acc" => Ok(Instruction::ACC(operand_value)), "jmp" => Ok(Instruction::JMP(operand_value)), - _ => Err(InstructionParseError::UnknownOpcode(instruction.to_string())), + _ => Err(InstructionParseError::UnknownOpcode( + instruction.to_string(), + )), } } } @@ -72,7 +78,11 @@ impl FromStr for Machine { impl Machine { fn pretty_print(&self) { for (idx, instr) in self.instructions.iter().enumerate() { - let pointer = if (idx as isize) == self.location { "--> " } else { " " }; + let pointer = if (idx as isize) == self.location { + "--> " + } else { + " " + }; println!("{} {:04}: {}", pointer, idx, instr); } } @@ -171,10 +181,13 @@ fn main() -> Result<(), TopLevelError> { // this is part 2 for mut variant in machine.variants() { if let Ok((true, final_value)) = variant.terminates() { - println!("\nFound a variant that halts! Its last value is {}", final_value); + println!( + "\nFound a variant that halts! Its last value is {}", + final_value + ); variant.pretty_print(); } } Ok(()) -} \ No newline at end of file +} diff --git a/src/bin/passport.rs b/src/bin/passport.rs index ba0188e..754c2b7 100644 --- a/src/bin/passport.rs +++ b/src/bin/passport.rs @@ -169,4 +169,4 @@ fn main() -> Result<(), TopLevelError> { ); Ok(()) -} \ No newline at end of file +} diff --git a/src/bin/password_check.rs b/src/bin/password_check.rs index 16336b5..8ce627e 100644 --- a/src/bin/password_check.rs +++ b/src/bin/password_check.rs @@ -96,4 +96,4 @@ fn main() -> Result<(), TopLevelError> { ); Ok(()) -} \ No newline at end of file +} diff --git a/src/bin/tobaggan.rs b/src/bin/tobaggan.rs index 8624277..c297583 100644 --- a/src/bin/tobaggan.rs +++ b/src/bin/tobaggan.rs @@ -90,4 +90,4 @@ fn main() -> Result<(), TopLevelError> { println!("The product of the trees encountered is {}", product); Ok(()) -} \ No newline at end of file +} diff --git a/src/errors.rs b/src/errors.rs index 7922498..fd43a09 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -108,14 +108,14 @@ impl<'a> From>> for BaggageRuleParseError { } } -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum InstructionParseError { #[error("Unknown opcode {0}")] UnknownOpcode(String), #[error("Couldn't convert number: {source}")] NumConversionError { #[from] - source: ParseIntError + source: ParseIntError, }, #[error("Encountered an empty instruction (?)")] EmptyInstruction, @@ -123,8 +123,8 @@ pub enum InstructionParseError { MissingOperand(String), } -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum ExecutionError { #[error("Tried to execute non-existent instruction at {0}")] NonExistentLocation(isize), -} \ No newline at end of file +}