libc
libc copied to clipboard
Provide zerocopy trait implementations behind feature flag
A common use of unsafe code is to access or modify the bytes of libc types (e.g. by transmuting them; here's an example). Many libc types could implement the zerocopy traits (FromBytes, AsBytes, and Unaligned) by using a custom derive, so this would just be a matter of adding #[cfg_attr(feature = "zerocopy", derive(FromBytes, AsBytes, Unaligned))] to the types which support it. This would allow all of those uses to be safe.
If this is something that the maintainers would be open to, I'd be happy to put up a PR.
This needs some level of team discussion since it would involve an ecosystem crate, I suggested a Zulip discussion on https://github.com/rust-lang/libc/pull/3924#issuecomment-2356572073. I don't really have any objection for an addition in 1.0 (or later) as long as it is pretty unintrusive.
Relevant PR: https://github.com/rust-lang/libc/pull/3407
This needs some level of team discussion since it would involve an ecosystem crate, I suggested a Zulip discussion on #3924 (comment). I don't really have any objection for an addition in 1.0 (or later) as long as it is pretty unintrusive.
I've started a Zulip thread.