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
[WIP] Add support for zerocopy traits via a feature. #498
Conversation
Thanks for the PR @mwanner! Since we’re looking to stabilize this crate I don’t think we can introduce any unstable public dependencies here. This seems like something that would be covered by the safer transmute API, but that’s still probably a ways off. Do you know if |
Allows uuid::Uuid to be read from or serialized to a byte slice without copying.
ed589fd
to
05d3321
Compare
Would implementing the trait for
Thanks for this link, I wasn't aware of this effort.
Not sure if that's what you're asking for, but there's e.g. |
The I don't think we could create a const |
Yes, sorry, that's what I meant. Is there currently a safe variant of the following thanks to
|
It looks like we don't currently have one, but we could add something like this in impl Uuid {
pub fn ref_from_bytes(data: &[u8; 16]) -> &Uuid;
} and deal with the unsafety in there. I'm not sure whether it would be valid to cast other types just yet, but it could be possible to also do |
Hi, folks. I'd like to help drive this PR forward. I didn't think to check the PR list for @KodrAus, could you help me understand this? "Since we’re looking to stabilize this crate I don’t think we can introduce any unstable public dependencies here." Is the requirement here that all dependencies of Also, can you clarify what you mean by "stabilize"? My impression of the Supporting |
Hey @sivadeilra 👋 The constraint we're working with is that any dependency that affects We have actually since added a |
Hi, thanks for responding.
Unfortunately, a newtype over I've worked with the owner of |
Ping, on my previous comment. |
Hmm, I wouldn’t want to put pressure on the |
Ah, I see, when it comes to implementing the traits the docs simply say “don’t” and they go to great effort to discourage you from implementing them directly. That’s a little unfortunate because it doesn’t give us many options to support it. As it is we’re a bit stuck then because we can’t implement unstable traits in |
If there’s no other option for you (such as using Would that work for your needs? |
Another option could be for Since I’m currently working on a stable |
I think the A bunch of us have been trying to push forward on supporting safe transmute traits directly in Would you accept the option of defining a feature for |
@sivadeilra I think I’d prefer we define the impl in It’s a bit of a shame just how disruptive semver bumps can be, even if there’s very little difference, but that’s the nature of it 🙂 |
I've opened a PR in #538 that adds unstable |
I think that's a good place to start. I do appreciate the requirements for stability, and not casually taking dependencies on crates that might change. Let's start with this, and I'll see if I can't nudge the safe-transmute process along. If that ever converges, then we can revisit this. Thanks! |
We’ve now added |
I'm submitting a feature proposal.
Description
Allows
uuid::Uuid
to be read from or serialized to a byte slice without copying by using the zerocopy crate.Motivation
I like the abstraction that zerocopy provides and UUIDs are often embedded in other structs I'd like to use zerocopy's traits on. Hiding this behind a feature that needs to be explicitly enabled should keep the general cost of this very low for the vast majority of users of uuid that do not use zerocopy.
Tests
Tests missing, therefore marked WIP.
Related Issue(s)
Not aware of any, possibly somewhat related to #472, though. Clearly adding another variant of
as_bytes()
via thezerocopy::AsBytes
trait.