I forgot the analogue of truncating the Vec. But here we can truncate
while it's still in cheap slice form, before making a Vec at all.
impl From<&[Word]> for FiniteNimber {
fn from(slice: &[Word]) -> FiniteNimber {
- match slice
+ match dbg!(slice
.iter()
.enumerate()
.rev()
- .find(|(_index, word)| **word != 0)
+ .find(|(_index, word)| **word != 0))
{
None => Self(FiniteNimberEnum::Single(0)),
Some((0, w)) => Self(FiniteNimberEnum::Single(*w)),
- Some(_) => Self(FiniteNimberEnum::Vector(slice.into()))
+ Some((pos, _)) => {
+ Self(FiniteNimberEnum::Vector(slice[..=pos].into()))
+ }
}
}
}