From 2e76e5faa196252c1ac8d16e75cc14adf1f71fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Thu, 7 Dec 2023 20:01:03 +0100 Subject: [PATCH] Remove unnecessary boxing --- 2023/day7/src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/2023/day7/src/main.rs b/2023/day7/src/main.rs index 66c6a8b..df31a83 100644 --- a/2023/day7/src/main.rs +++ b/2023/day7/src/main.rs @@ -33,7 +33,7 @@ enum HandType { trait Parse { type Out; - fn parse(s: &str) -> IResult<&str, Box>; + fn parse(s: &str) -> IResult<&str, Self::Out>; } #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] @@ -72,11 +72,11 @@ enum CardWithJoker { impl Parse for CardWithoutJoker { type Out = Self; - fn parse(s: &str) -> IResult<&str, Box> { + fn parse(s: &str) -> IResult<&str, Self> { let (rest, c) = anychar(s)?; Ok(( rest, - Box::new(match c { + match c { '2' => Self::Two, '3' => Self::Three, '4' => Self::Four, @@ -96,18 +96,18 @@ impl Parse for CardWithoutJoker { nom::error::ErrorKind::Char, ))) } - }), + }, )) } } impl Parse for CardWithJoker { type Out = Self; - fn parse(s: &str) -> IResult<&str, Box> { + fn parse(s: &str) -> IResult<&str, Self> { let (rest, c) = anychar(s)?; Ok(( rest, - Box::new(match c { + match c { '2' => Self::Two, '3' => Self::Three, '4' => Self::Four, @@ -127,7 +127,7 @@ impl Parse for CardWithJoker { nom::error::ErrorKind::Char, ))) } - }), + }, )) } } @@ -191,7 +191,6 @@ trait ParseHand { Box::new(Self::Out::from_vec( cards .into_iter() - .map(|card| *card) .collect::::CardType>>(), )), ))