I'm implementing FromIterator
for [MyStruct;4]
where MyStruct
is a small Copy struct. My current implementation is
fn from_iter<I: IntoIterator<Item=MyStruct>>(iter: I) -> Self {
let mut retval = [Default::default();4];
for (ret, src) in retval.iter_mut().zip(iter) {
*ret = src;
}
retval
}
This works just fine, however I'm not sure that the for
loop is as idiomatic as it could be. Is there perhaps a method like Slice::fill(iter)
that could accomplish this more cleanly (and perhaps more efficiently)?