libc icon indicating copy to clipboard operation
libc copied to clipboard

Provide zerocopy trait implementations behind feature flag

Open joshlf opened this issue 2 years ago • 1 comments

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.

joshlf avatar Aug 09 '23 22:08 joshlf

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

tgross35 avatar Sep 17 '24 18:09 tgross35

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.

joshlf avatar Sep 18 '24 16:09 joshlf