diff --git a/src/bin/ferry.rs b/src/bin/ferry.rs index d2247c0..4f30970 100644 --- a/src/bin/ferry.rs +++ b/src/bin/ferry.rs @@ -40,10 +40,12 @@ impl Into for FerryLocation { } } +type ViewerResult = Result, MapOperationError>; + struct EvolvingMap { next_map: Option>, occupation_tolerance: usize, - view: fn(&Map, usize, usize) -> Result, MapOperationError>, + view: fn(&Map, usize, usize) -> ViewerResult, } impl From> for EvolvingMap { diff --git a/src/bin/machine.rs b/src/bin/machine.rs index 1b38001..04a85d5 100644 --- a/src/bin/machine.rs +++ b/src/bin/machine.rs @@ -30,7 +30,7 @@ impl FromStr for Instruction { let instruction = items .next() .ok_or(InstructionParseError::EmptyInstruction)?; - let operand = items.next().ok_or(InstructionParseError::MissingOperand( + let operand = items.next().ok_or_else(|| InstructionParseError::MissingOperand( instruction.to_string(), ))?; let operand_value = isize::from_str(operand)?; @@ -165,7 +165,7 @@ impl Iterator for VariantGenerator { } fn main() -> Result<(), TopLevelError> { - let filename = env::args().skip(1).next().expect("No file argument given."); + let filename = env::args().nth(1).expect("No file argument given."); let contents = fs::read_to_string(filename)?; let machine = Machine::from_str(&contents)?; diff --git a/src/bin/xmas.rs b/src/bin/xmas.rs index 4787f78..707d52e 100644 --- a/src/bin/xmas.rs +++ b/src/bin/xmas.rs @@ -116,7 +116,7 @@ fn third_example() { } fn main() -> Result<(), TopLevelError> { - let filename = env::args().skip(1).next().expect("No file argument given."); + let filename = env::args().nth(1).expect("No file argument given."); let contents = fs::read_to_string(filename)?; let mut xmas_checker = XmasChecker::new(25); diff --git a/src/map.rs b/src/map.rs index 6cc12c2..043b3d1 100644 --- a/src/map.rs +++ b/src/map.rs @@ -54,7 +54,7 @@ impl Map { pub fn at_unwrapped(&self, x: usize, y: usize) -> Option { let row = self.data.get(y)?; - row.get(x).map(|x| x.clone()) + row.get(x).cloned() } fn view(&self, f: fn(&X) -> bool, x: usize, y: usize, rise: isize, run: isize) -> Option { @@ -125,7 +125,7 @@ impl Map { Ok(results) } - pub fn locations<'a>(&'a self) -> MapLocations<'a, X> { + pub fn locations(&self) -> MapLocations { MapLocations { underlying: self, x: 0, @@ -176,7 +176,7 @@ impl> Map { for x in 0..self.width { print!("{}", self.at(x, y).unwrap().into()); } - println!(""); + println!(); } } }