aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2019-12-05 18:11:05 +1000
committerGravatar alecdwm 2019-12-05 18:11:05 +1000
commit76a7b1278b73c113491b7a98b2750ceec5377510 (patch)
tree2cf493b74c958f0437ce5ac7d27869516c692b64
parent386f27df5b962cd83a728b886145debcd398d512 (diff)
fixed clippy suggestions
-rw-r--r--src/main.rs2
-rw-r--r--src/year_2018/day1.rs2
-rw-r--r--src/year_2018/day7.rs2
-rw-r--r--src/year_2019/day2.rs4
-rw-r--r--src/year_2019/day3.rs4
-rw-r--r--src/year_2019/day4.rs2
-rw-r--r--src/year_2019/intcode_computer.rs23
7 files changed, 20 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 8b1b3b1..5ecd329 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,7 +30,7 @@ fn main() {
puzzle_solutions.insert("2019::day5::part1", advent_of_code::year_2019::day5::part1);
puzzle_solutions.insert("2019::day5::part2", advent_of_code::year_2019::day5::part2);
- let command = match env::args().skip(1).next() {
+ let command = match env::args().nth(2) {
Some(command) => command,
None => {
eprintln!(
diff --git a/src/year_2018/day1.rs b/src/year_2018/day1.rs
index c99e2f9..cd3d323 100644
--- a/src/year_2018/day1.rs
+++ b/src/year_2018/day1.rs
@@ -105,7 +105,7 @@ fn build_changes(input: &str) -> Vec<FrequencyChange> {
magnitude: line
.trim_start_matches(|c| c == '+' || c == '-')
.parse()
- .expect(&format!("parsing frequency change magnitude '{}'", line)),
+ .unwrap_or_else(|_| panic!("parsing frequency change magnitude '{}'", line)),
})
}
diff --git a/src/year_2018/day7.rs b/src/year_2018/day7.rs
index c926ca7..ebbfabe 100644
--- a/src/year_2018/day7.rs
+++ b/src/year_2018/day7.rs
@@ -197,7 +197,7 @@ impl StepGraph {
}
fn next_step(&mut self, complete_step: bool) -> Option<char> {
- if self.available_steps.len() < 1 {
+ if self.available_steps.is_empty() {
return None;
}
diff --git a/src/year_2019/day2.rs b/src/year_2019/day2.rs
index 136231f..ca8621a 100644
--- a/src/year_2019/day2.rs
+++ b/src/year_2019/day2.rs
@@ -89,7 +89,7 @@ pub fn part2() {
let program = IntcodeProgram::from(input.as_str());
let mut computer = IntcodeComputer::from(&program);
- const DESIRED_OUTPUT: i64 = 19690720;
+ const DESIRED_OUTPUT: i64 = 19_690_720;
let mut result = None;
'outer: for noun in 0..100 {
@@ -99,7 +99,7 @@ pub fn part2() {
computer = computer.run();
- if *computer.memory.get(0) == DESIRED_OUTPUT {
+ if computer.memory.get(0) == DESIRED_OUTPUT {
result = Some((noun, verb));
break 'outer;
}
diff --git a/src/year_2019/day3.rs b/src/year_2019/day3.rs
index 2b68108..17dee26 100644
--- a/src/year_2019/day3.rs
+++ b/src/year_2019/day3.rs
@@ -129,7 +129,7 @@ impl Default for Wire {
impl Wire {
fn parse_wires(serialized: &str) -> Vec<Self> {
- serialized.trim().split("\n").map(Wire::from).collect()
+ serialized.trim().split('\n').map(Wire::from).collect()
}
fn intersections(&self, target: &Wire) -> Vec<Point> {
@@ -272,7 +272,7 @@ impl From<&str> for Wire {
wire_serialized
.trim()
- .split(",")
+ .split(',')
.for_each(|wire_segment| wire.add_point_from_segment(wire_segment));
wire
diff --git a/src/year_2019/day4.rs b/src/year_2019/day4.rs
index 158e82f..c95c507 100644
--- a/src/year_2019/day4.rs
+++ b/src/year_2019/day4.rs
@@ -121,7 +121,7 @@ impl FromStr for ops::RangeInclusive<i64> {
fn from_str(string: &str) -> Self {
let mut iter = string
.trim()
- .split("-")
+ .split('-')
.map(|integer| integer.parse())
.map(|parse_result| parse_result.expect("Failed to parse range integer as i64"));
diff --git a/src/year_2019/intcode_computer.rs b/src/year_2019/intcode_computer.rs
index 74665e2..e2cc9e9 100644
--- a/src/year_2019/intcode_computer.rs
+++ b/src/year_2019/intcode_computer.rs
@@ -204,8 +204,8 @@ impl IntcodeInstruction {
impl From<&IntcodeComputer> for IntcodeInstruction {
fn from(state: &IntcodeComputer) -> Self {
let instruction_header = state.memory.get(state.instruction_pointer);
- let opcode = Opcode::from(*instruction_header);
- let mut parser = ParameterParser::from(*instruction_header);
+ let opcode = Opcode::from(instruction_header);
+ let mut parser = ParameterParser::from(instruction_header);
match opcode {
Opcode(1) => Self::Add(
@@ -275,7 +275,7 @@ impl IntcodeParameter {
fn get_value(&self, memory: &IntcodeProgram) -> i64 {
match self {
- Self::Position(address) => *memory.get(*address),
+ Self::Position(address) => memory.get(*address),
Self::Value(value) => *value,
}
}
@@ -297,13 +297,13 @@ impl From<i64> for ParameterParser {
}
impl ParameterParser {
- fn parse_next(&mut self, parameter: &i64) -> IntcodeParameter {
+ fn parse_next(&mut self, parameter: i64) -> IntcodeParameter {
let mode = ParameterMode::from(&*self);
let parameter = match mode {
ParameterMode::PositionMode => {
- IntcodeParameter::Position((*parameter).try_into().unwrap())
+ IntcodeParameter::Position(parameter.try_into().unwrap())
}
- ParameterMode::ImmediateMode => IntcodeParameter::Value(*parameter),
+ ParameterMode::ImmediateMode => IntcodeParameter::Value(parameter),
};
self.parameters_read += 1;
@@ -311,8 +311,8 @@ impl ParameterParser {
parameter
}
- fn parse_writeonly(&mut self, parameter: &i64) -> IntcodeParameter {
- let parameter = IntcodeParameter::Position((*parameter).try_into().unwrap());
+ fn parse_writeonly(&mut self, parameter: i64) -> IntcodeParameter {
+ let parameter = IntcodeParameter::Position(parameter.try_into().unwrap());
self.parameters_read += 1;
@@ -342,8 +342,9 @@ pub struct IntcodeProgram {
}
impl IntcodeProgram {
- pub fn get(&self, address: usize) -> &i64 {
- self.data
+ pub fn get(&self, address: usize) -> i64 {
+ *self
+ .data
.get(address)
.unwrap_or_else(|| panic!("Failed to get data at address {}", address))
}
@@ -375,7 +376,7 @@ impl From<&str> for IntcodeProgram {
Self {
data: string
.trim()
- .split(",")
+ .split(',')
.map(|integer| integer.parse::<i64>())
.map(|parse_result| parse_result.expect("Failed to parse Intcode integer as i64"))
.collect(),