summaryrefslogtreecommitdiff
path: root/2021/rust/day02/src
diff options
context:
space:
mode:
authorcos <cos>2021-12-02 12:00:15 +0100
committercos <cos>2021-12-02 12:00:17 +0100
commitbb990ebffc3044fc0eb975a225ca6541c61f7f69 (patch)
tree23c6a3c67659c388b5296da9e41242ccb78f81c9 /2021/rust/day02/src
parent8d207663b8c561e27e1dd50a7523ed6b62c8e1cd (diff)
downloadadventofcode-bb990ebffc3044fc0eb975a225ca6541c61f7f69.zip
Use trait to increase flexibility
By using IntoIterator, the changed functions become more flexible in what input they accept.
Diffstat (limited to '2021/rust/day02/src')
-rw-r--r--2021/rust/day02/src/main.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/2021/rust/day02/src/main.rs b/2021/rust/day02/src/main.rs
index 4178ecc..d093dba 100644
--- a/2021/rust/day02/src/main.rs
+++ b/2021/rust/day02/src/main.rs
@@ -91,7 +91,7 @@ fn read_input<T: AsRef<Path>>(filename: T) -> Result<Vec<Command>> {
).collect()
}
-fn part1(input: &[Command]) -> Result<Position> {
+fn part1<'a, I: IntoIterator<Item = &'a Command>>(input: I) -> Result<Position> {
let mut position = Position { x: 0, y:0 };
for command in input {
match command {
@@ -104,7 +104,7 @@ fn part1(input: &[Command]) -> Result<Position> {
Ok(position)
}
-fn part2(input: &[Command]) -> Result<Position> {
+fn part2<'a, I: IntoIterator<Item = &'a Command>>(input: I) -> Result<Position> {
let mut position = Position { x: 0, y:0 };
let mut aim = 0;
for command in input {