-
Notifications
You must be signed in to change notification settings - Fork 113
Support generic NonZero<T> #2255
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
Comments
Sure, I'd be happy to provide mentorship. If you'd like to take this on, the first step is to adapt this documentation on /// # Layout
///
/// `NonZero<T>` is guaranteed to have the same layout and bit validity as `T`
/// with the exception that the all-zero bit pattern is not a valid instance.
///
/// `Option<NonZero<T>>` is is guaranteed to be compatible with `T`, including
/// in FFI.
///
/// Thanks to the [null pointer optimization], `NonZero<T>` and
/// `Option<NonZero<T>>` are guaranteed to have the same size and alignment.
///
/// [null pointer optimization]: crate::option#representation
Then, once that lands, submit a PR simplifying and genericizing these impls: Lines 245 to 365 in f495088
|
Thanks @jswrenn for the guidance! I've submitted the doc change and will work on the zerocopy change once that lands. Seeing as |
Sounds good! Base your zerocopy PR off the |
Ok, I started the implementation and quickly realized that I had completely misunderstood the root issue. The problem is not that zerocopy is missing a generic To repeat my original use case for clarity, my goal is that zerocopy is able to realize that #[derive(TryFromBytes, KnownLayout, IntoBytes, Immutable)]
#[repr(transparent)]
pub struct LSN(NonZeroU64);
// this currently fails
#[derive(TryFromBytes, KnownLayout, IntoBytes, Immutable)]
#[repr(C)]
pub struct Foo {
lsn: Option<LSN>
} I should have realized this sooner, sorry about that. I still think that adding Layout docs to Unfortunately, I'm not aware of a way to detect a In addition, In conclusion, adding |
I looked into this a bit more, and IMO I don't think it's possible for us to support this. In particular, the current definition of pub struct NonZero<T>(/* private fields */)
where
T: ZeroablePrimitive In order to add a generic implementation for I've closed this, but feel free to keep commenting here. |
What is the name of your project?
An unreleased but in-development storage engine that will power SQLSync v2.
Please provide a link to your project (GitHub repository, crates.io page, etc).
https://github.com/orbitinghail/sqlsync
https://github.com/orbitinghail
What features would you like from zerocopy?
I'd like zerocopy to handle the new generic
NonZero<T>
type in the same way as it handles otherNonZero
types. I'm happy to take a crack at this if it's straightforward and doesn't have any soundness errors.This feature is already listed here #1120 but I'd like to raise it as a more current issue in order to get it resolved (assuming it doesn't have any soundness issues).
My current workaround is definining a type like so:
The downside of the above is an additional wrapping/unwrapping layer and a lot of generated code. It probably gets compiled out of the actual binary, but it adds unneeded complexity.
Once this issue is resolved, I should be able to replace usages of
MaybeLSN
withOption<LSN>
.I'm happy to fix this myself if that would be acceptable and someone is available to help check the soundness of the implementation.
Thanks for an AMAZING project btw. I love zerocopy.
The text was updated successfully, but these errors were encountered: