-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally implement Zeroable
and Pod
from bytemuck
#12
Conversation
Is this for anything in particular? I'd prefer to keep rend as slim as possible, and there are some alternatives which make the choice of support unclear. |
I'm not exactly sure what you mean by "for anything in particular". I've simply added a feature that exists in version 0.4.1 and 0.4.2 (via #10) that does not yet exist in 0.5. Note: You did express the intent of support for bytemuck in version 0.5 as well: |
Zeroable
and Pod
from bytemuckZeroable
and Pod
from bytemuck
rend is explicitly by and for rkyv, and so caters pretty directly to rkyv's needs. That's why rend supports bytecheck, for example. So if more people/projects are interested in using rend, I'd like to know what use cases need bytemuck support (as an example) before adding it. Adding support is committing to the integration after all, and I'd like to have some idea of what the future use is before adding it.
I did, and my stance has shifted since then having maintained a bunch of crate integrations for rkyv. At the time, I also saw potential in using bytemuck in rkyv, but that didn't pan out and I'm happy in my little rkyv ecosystem I've built up. |
That's fair enough I suppose. I will preface this by saying that I don't use rkyv. My use case is a short experiment I'm doing in filesystems and partitioning. As a short example, consider the following data structure, the GPT Partition Table Header: use bytemuck::{Zeroable, Pod};
use rend::{u32_le, u64_le};
#[derive(Zeroable, Pod)]
#[repr(C)]
pub struct PartitionTableHeader {
pub signature: [u8; 8],
pub revision: u32_le,
pub header_size: u32_le,
pub crc32_checksum: u32_le,
pub _reserved: [u8; 4],
pub lba_of_this_header: u64_le,
pub lba_of_alternate_header: u64_le,
pub first_usable_block: u64_le,
pub last_usable_block: u64_le,
pub disk_guid: [u8; 16],
pub lba_of_entry_array: u64_le,
pub partition_entry_count: u32_le,
pub size_of_partition_entry: u32_le,
pub partition_entry_array_crc32: u32_le,
// Required so that there is no padding, otherwise `Pod`'s constraints are unfulfilled.
// This could alternatively be solved using rend's unaligned types and `#[repr(C, packed)]`.
pub _reserved2: [u8; 36],
} In this case, because the in-memory representation is exactly what should be read from and written to disk (including endianness), I can just cast the struct using bytemuck and move on to do more important things.
The 5 alternatives I listed are mostly hypotheticals (apart from 1, which I actually did try before scrapping it because as one might expect, it was not a pleasant experience). |
Hey @tecc, I came across this because I'm in the process of adding zerocopy support to rend. It sounds like zerocopy's |
`Zeroable` and `Pod` has been implemented for all unsigned integers, signed integers and floats. Additionally, `Zeroable` has been implemented for `char` types.
783038d
to
28764f8
Compare
Sorry for the delay. After taking some more time to think about it and receiving a few more requests for this feature, I'm okay with adding support for bytemuck. Thanks for the PR, I appreciate your hard work! |
(Apologies for the late reply, I've been busy so I forgot)
That's not a particularly bad idea either, though it'd mean I'd have to strip out my use of bytemuck and replace it with zerocopy.
Thank you for merging it! |
This PR adds implementations for
Zeroable
andPod
to some types in rend where they are applicable.These traits do not get implemented unless the
bytemuck
feature is enabled.Specifically, at the time of writing:
traits.rs
:unsafe_impl_zeroable
andunsafe_impl_pod
.Zeroable
andPod
impls have been added for the unsigned integers, signed integers, and floats.Zeroable
has been implemented forchar
.I refrained from implementing these values for atomics and other variations of the Zeroable/Pod types. Those require more features to be enabled on the bytemuck crate.