Replies: 3 comments 1 reply
-
It looks like Fuchsia currently uses EDIT: My initial search was too narrow, we also do this when we generate bindings to the Linux uapi. |
Beta Was this translation helpful? Give feedback.
-
The ppv-lite86 crate uses |
Beta Was this translation helpful? Give feedback.
-
I have a similar usage to this one in a private project for versioned binary blobs. The classic approach #[derive(TryFromBytes, Immutable, IntoBytes)]
#[repr(C)]
pub enum Blob {
V1(BlobV1),
V2(BlobV2),
} doesn't work because enums cannot be packed so I have to rewrite them as #[derive(TryFromBytes, Immutable, IntoBytes)]
#[repr(C, packed)]
pub struct Blob {
version: BlobVersion,
blob: BlobUnion
}
#[derive(TryFromBytes, IntoBytes, Immutable)]
#[repr(u8)]
pub enum BlobVersion {
V1,
V2,
}
#[derive(TryFromBytes, IntoBytes, Immutable)]
union BlobUnion {
v1: BlobV1,
v2: BlobV2,
} with some extra code for conversions. Also, unsafe impl IntoBytes for BlobUnion myself and there every field type is checked by |
Beta Was this translation helpful? Give feedback.
-
Tracking issue: #1792
TL;DR: If you want to use
IntoBytes
with union types, upvote this discussion!In 0.8, we've restricted
#[derive (IntoBytes)]
so that it only supports unions when—-cfg zerocopy_derive_union_into_bytes
ispassed. Union bit validity is up in the air, and it's not currently guaranteed that implementing IntoBytes on unions will remain
sound on all future Rust versions.
The exact bit validity of unions is actively being discussed, and we're advocating for bit validity requirements that will permit
IntoBytes
on unions to be sound.If you would like to use
IntoBytes
with unions, please let us know by upvoting this discussion or by commenting. We will usethis as evidence that there is demand for this feature, and try to persuade Rust to adopt the necessary union bit validity
requirements. Please do not spam other threads besides this one, especially threads in rust-lang repositories. Let's be friendly
participants in this discussion 🙂
Beta Was this translation helpful? Give feedback.
All reactions