-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Martin Geisler <[email protected]>
Hi @semihbkgr, please run |
Thanks for the help, this is super useful! |
Head branch was pushed to by a user without write access
src/unsafe-rust/unsafe-traits.md
Outdated
// 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 {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
Zerocopy crate version 0.8 introduced changes to its API, which caused the example code to break.
google/zerocopy#1680