| ▲ | tialaramex a day ago | |
Your code snippet is fine, but MaybeUninit comes into its own when it's not obvious to the compiler that what you wrote is OK - MaybeUninit::assume_init is how you tell the compiler "I promise this is correctly initialized" and so long as you're correct, everything is fine. By Rice's Theorem no compiler could ever be sure all the time, and in fact Rust choose to be extremely pessimistic, obvious things like yours work, non-obvious things do not and if you write a ticket about a case you feel ought to be obvious but was not (please don't) the Rust folks will say that is as intended, here are some alternatives to achieve what you meant, up to and including MaybeUninit | ||