Another Experiment To Make Unsafe Rust Safer: Preventing UB In MaybeUninit With Compile Time Error
fuji-184:
My goal is a lossless safer abstraction of maybeuninit. So that it can still be used as building block to create data structure or low level programming
But now I'm confused to choose compile time error, zero branching, but 2 different type because it is what causes the compile time error so no branching is needed. Or 1 type but using runtime branching
You’re approaching this problem too abstractly. Both of the possibilities you have named are usually already possible in safer ways (static checks with ordinary functions returning values of different types, and dynamic checks with Option). MaybeUninit is used in cases where neither of those approaches apply.
You cannot design a better MaybeUninit by just thinking about what additional checks would make it safer to use. What you need to do is:
- Find specific existing code that uses
MaybeUninit. - Think about how that code uses
MaybeUninitand what it actually needs. - Design something that is safer and make sure that code can be rewritten to use it.
- Apply this to other code too, in order to show that it is useful in more than one situation.
Validate your design by showing that it can improve existing real-world unsafe code.
fuji-184:
1 type with optional written len for array. Or dedicated type for array with name UninitArray (MaybeUninit<[ array ]>). That will have method to get slice from it as long as it is < the written len, no need to wait it to be fully written
This is what ArrayVec does. You don’t need to write this type because it already exists.
Discussion in the ATmosphere