Skip to content

Commit

Permalink
use new raw pointer expression
Browse files Browse the repository at this point in the history
  • Loading branch information
semihbkgr committed Oct 28, 2024
1 parent 792399d commit 3d53ec2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/unsafe-rust/unsafe-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ use std::{mem, slice};
pub unsafe trait IntoBytes {
fn as_bytes(&self) -> &[u8] {
let len = mem::size_of_val(self);
let slf: *const Self = self;
unsafe { slice::from_raw_parts(slf.cast::<u8>(), len) }
unsafe { slice::from_raw_parts((&raw const self).cast::<u8>(), len) }
}
}
/// SAFETY: `u32` has no padding bytes.
// SAFETY: `u32` has a defined representation and no padding.
unsafe impl IntoBytes for u32 {}
```

Expand Down

0 comments on commit 3d53ec2

Please sign in to comment.