Remove unnecessary boxing

This commit is contained in:
2023-12-07 20:01:03 +01:00
parent 1e17292b18
commit 2e76e5faa1

View File

@@ -33,7 +33,7 @@ enum HandType {
trait Parse { trait Parse {
type Out; type Out;
fn parse(s: &str) -> IResult<&str, Box<Self::Out>>; fn parse(s: &str) -> IResult<&str, Self::Out>;
} }
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
@@ -72,11 +72,11 @@ enum CardWithJoker {
impl Parse for CardWithoutJoker { impl Parse for CardWithoutJoker {
type Out = Self; type Out = Self;
fn parse(s: &str) -> IResult<&str, Box<Self>> { fn parse(s: &str) -> IResult<&str, Self> {
let (rest, c) = anychar(s)?; let (rest, c) = anychar(s)?;
Ok(( Ok((
rest, rest,
Box::new(match c { match c {
'2' => Self::Two, '2' => Self::Two,
'3' => Self::Three, '3' => Self::Three,
'4' => Self::Four, '4' => Self::Four,
@@ -96,18 +96,18 @@ impl Parse for CardWithoutJoker {
nom::error::ErrorKind::Char, nom::error::ErrorKind::Char,
))) )))
} }
}), },
)) ))
} }
} }
impl Parse for CardWithJoker { impl Parse for CardWithJoker {
type Out = Self; type Out = Self;
fn parse(s: &str) -> IResult<&str, Box<Self>> { fn parse(s: &str) -> IResult<&str, Self> {
let (rest, c) = anychar(s)?; let (rest, c) = anychar(s)?;
Ok(( Ok((
rest, rest,
Box::new(match c { match c {
'2' => Self::Two, '2' => Self::Two,
'3' => Self::Three, '3' => Self::Three,
'4' => Self::Four, '4' => Self::Four,
@@ -127,7 +127,7 @@ impl Parse for CardWithJoker {
nom::error::ErrorKind::Char, nom::error::ErrorKind::Char,
))) )))
} }
}), },
)) ))
} }
} }
@@ -191,7 +191,6 @@ trait ParseHand {
Box::new(Self::Out::from_vec( Box::new(Self::Out::from_vec(
cards cards
.into_iter() .into_iter()
.map(|card| *card)
.collect::<Vec<<Self::Out as Hand>::CardType>>(), .collect::<Vec<<Self::Out as Hand>::CardType>>(),
)), )),
)) ))