bytemuck
bytemuck copied to clipboard
Good Idea: safe way to transmute `Vec<Option<&Foo>>` to `Vec<&Foo>`
https://www.reddit.com/r/rust/comments/1ez6f2c/any_safe_way_to_transmute_vecoptionfoo_to_vecfoo/
So yeah, what we want is to be able to convert from Option<&i32> to &i32, particularly within a vec/slice/container.
There's lots of types with guaranteed option representation, so we probably want to use some sort of trait.
Isn't this only possible going from &[&Foo] to &[Option<&Foo>] and not the other way around? Or do you mean that in the owned Vec case, we should check all values are Some before doing the transmute?
The latter case, we'd do a check then convert if it's valid.