Skip to content

Remove some unsafe; stabilize zerocopy #833

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshlf
Copy link

@joshlf joshlf commented Jul 8, 2025

Remove a number of unsafe blocks, replacing them with uses of zerocopy. In order to do this, we stabilize zerocopy as a (non-optional) dependency.

Closes #588

Remove a number of `unsafe` blocks, replacing them with uses of
zerocopy. In order to do this, we stabilize zerocopy as a (non-optional)
dependency.

Closes uuid-rs#588
@KodrAus
Copy link
Member

KodrAus commented Jul 9, 2025

Thanks for the PR @joshlf! I'm not immediately in favour of adding a non-optional dependency on zerocopy to remove a handful of unsafe blocks. Since it's also still technically unstable we're not able to accept a public dependency on it here anyways.

As an aside, it would be really nice to see some support for the common pattern of transmuting values of #[repr(transparent)] NewType(T) to T without needing an unsafe block in the language or standard library.

@@ -194,58 +252,59 @@ const fn format_hyphenated(src: &[u8; 16], upper: bool) -> [u8; 36] {
#[inline]
fn encode_simple<'b>(src: &[u8; 16], buffer: &'b mut [u8], upper: bool) -> &'b mut str {
let buf = &mut buffer[..Simple::LENGTH];
let dst = buf.as_mut_ptr();
let buf: &mut [u8; Simple::LENGTH] = buf.try_into().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup 👍

@joshlf
Copy link
Author

joshlf commented Jul 9, 2025

No worries! Feel free to steal the non-zerocopy changes from this PR.

As an aside, it would be really nice to see some support for the common pattern of transmuting values of #[repr(transparent)] NewType(T) to T without needing an unsafe block in the language or standard library.

Hopefully the Safe Transmute APIs will support this once they land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for zerocopy
2 participants