which builds a new array of Foo (which is repr(C) but requires some masking and validation on the input byte pattern) out of an appropriately-sized byte view.
Is this key pattern of array::from_fn({let view = must_cast_ref(…); |i| construct(&view[i])}) a good practice, or am I going about it the wrong way?
Replacing must_cast_ref with chunks_exact seems to trade compile-time typo checking for run-time checks that silently ignore mistakes. Are there any benefits to doing that?
Usually the .try_into().unwrap() optimizes out. Not sure if .next().unwrap() does but yours also has view[i] so it's probably not much different. If you want something that doesn't panic you can map the whole thing.
Yeah, that's just my guesses though. The only thing the second one doesn't check is that std::mem::size_of::<Foo>() is the same as what construct_one_foo takes, but this kind of thing would either be typo-free or fail every time, so it's not really a risk.
If you're just going for readability, any of them should work. If you want to know which is faster, you'll have to test them.