Skip to content

Commit deb8871

Browse files
roypatbonzini
authored andcommitted
refactor: impl ByteValued::as_bytes via as_mut_slice
It's the same cast that happens, but like this we can use the `From<&mut [u8]>` impl for VolatileSlice and avoid an unsafe block. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent be06c46 commit deb8871

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/bytes.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,8 @@ pub unsafe trait ByteValued: Copy + Send + Sync {
113113

114114
/// Converts a mutable reference to `self` into a `VolatileSlice`. This is
115115
/// useful because `VolatileSlice` provides a `Bytes<usize>` implementation.
116-
///
117-
/// # Safety
118-
///
119-
/// Unlike most `VolatileMemory` implementation, this method requires an exclusive
120-
/// reference to `self`; this trivially fulfills `VolatileSlice::new`'s requirement
121-
/// that all accesses to `self` use volatile accesses (because there can
122-
/// be no other accesses).
123116
fn as_bytes(&mut self) -> VolatileSlice {
124-
// SAFETY: This is safe because the lifetime is the same as self
125-
unsafe { VolatileSlice::new(self as *mut Self as *mut _, size_of::<Self>()) }
117+
VolatileSlice::from(self.as_mut_slice())
126118
}
127119
}
128120

0 commit comments

Comments
 (0)