Skip to content
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

Update unsafe trait example to zerocopy version 0.8 #2434

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

semihbkgr
Copy link
Contributor

Zerocopy crate version 0.8 introduced changes to its API, which caused the example code to break.
google/zerocopy#1680

AsBytes -> IntoBytes

@mgeisler mgeisler changed the title Update unsafe trait example to address zerocopy API changes in version 0.8 Update unsafe trait example zerocopy version 0.8 Oct 16, 2024
@mgeisler mgeisler changed the title Update unsafe trait example zerocopy version 0.8 Update unsafe trait example to zerocopy version 0.8 Oct 16, 2024
@mgeisler
Copy link
Collaborator

Hi @semihbkgr, please run dprint fmt to fix the formatting (or apply it by hand from the output of the failing test). Then we can merge this!

@mgeisler mgeisler enabled auto-merge (squash) October 18, 2024 07:11
@mgeisler
Copy link
Collaborator

Thanks for the help, this is super useful!

auto-merge was automatically disabled October 18, 2024 20:02

Head branch was pushed to by a user without write access

// SAFETY: `u32` has a defined representation and no padding.
unsafe impl AsBytes for u32 {}
/// Types which are free from interior mutability.
pub unsafe trait Immutable {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mgeisler, I think it had to be added to make the tests pass.

Copy link
Collaborator

@fw-immunant fw-immunant Oct 18, 2024

Choose a reason for hiding this comment

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

Shouldn't we still have a SAFETY comment here, given the unsafe impl?

EDIT: Oh, I misread this change. It would be ideal for this slide to still actually demonstrate an unsafe impl as that is the unsafe capability being discussed here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

EDIT: Oh, I misread this change. It would be ideal for this slide to still actually demonstrate an unsafe impl as that is the unsafe capability being discussed here.

Yeah, I agree we should keep the unsafe impl.

@semihbkgr, could you simplify the IntoBytes trait and remove the where Self: Immutable bound? The code has to be super simple and just demonstrate the concept of an unsafe trait (it should not be 100% like what zerocopy has).

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.

3 participants