From bb990ebffc3044fc0eb975a225ca6541c61f7f69 Mon Sep 17 00:00:00 2001 From: cos Date: Thu, 2 Dec 2021 12:00:15 +0100 Subject: Use trait to increase flexibility By using IntoIterator, the changed functions become more flexible in what input they accept. --- 2021/rust/day02/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '2021/rust/day02/src') 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>(filename: T) -> Result> { ).collect() } -fn part1(input: &[Command]) -> Result { +fn part1<'a, I: IntoIterator>(input: I) -> Result { let mut position = Position { x: 0, y:0 }; for command in input { match command { @@ -104,7 +104,7 @@ fn part1(input: &[Command]) -> Result { Ok(position) } -fn part2(input: &[Command]) -> Result { +fn part2<'a, I: IntoIterator>(input: I) -> Result { let mut position = Position { x: 0, y:0 }; let mut aim = 0; for command in input { -- cgit v1.2.3