Lokathor / bytemuck

A crate for mucking around with piles of bytes
https://docs.rs/bytemuck
Apache License 2.0
697 stars 77 forks source link

impl `ZeroableInOption` for all `Zeroable`? #246

Open Rua opened 3 months ago

Rua commented 3 months ago

Currently, Option<NonZeroI32> implements Zeroable, but Option<i32> does not. Would it be sound to implement ZeroableInOption for all Zeroable types? Since zero maps to None in a regular option, this would always produce a valid value wouldn't it?

Lokathor commented 3 months ago

The compiler doesn't guarantee that None has a tag value of 0 when it has a separately stored tag.

In practice, in current rust, i believe this is what would occur, but it would only be by coincidence, not a stability promise.