[Pitch 2] Safe loading of values from `RawSpan`

really? reading from uninitialized bytes is undefined behavior. safe code shouldn’t have to assume other parts of the program exhibit undefined behavior and defend against it, right?

seeing this and Possible unsoundness with RawSpan and MutableRawSpan - #8 by ellie20 makes me concerned for the safety and soundness of these APIs, which are intended to be entirely safe alternatives to using raw pointers.

i really like @ellie20's suggestion of BitwiseLoadable and BitwiseStorable protocols, for fully inhabited types with and without padding respectively. perhaps later proposals could add something like a BitwiseLoadableButWithAValidationStep for types like Range.

ouu! and i’d throw in CollectionOfOne conditionally while we’re at it!

1 Like