collect()
on iterable to Vec
RS-P1006Collecting Iterator
to Vec
has the possible cost of forcing allocation,
hence instead directly using the iterator is more efficient quite often,
if the Vec
is unnecessary.
Consider replacing,
.collect::<Vec<_>>().len()
with .count()
..collect::<Vec<_>>().is_empty()
with .next().is_none()
.(0..5).collect::<Vec<_>>().len()
(0..5).count()