This commit is contained in:
Rune Tynan
2023-03-01 20:27:03 -05:00
parent 3a87a18857
commit f26b0a2948
@@ -42,10 +42,7 @@ pub trait AllocBytes:
/// Create a zeroed `AllocBytes` of the specified size and alignment;
/// call the callback error handler if there is an error in allocating the memory.
fn zeroed(
size: Size,
_align: Align,
) -> Option<Self>;
fn zeroed(size: Size, _align: Align) -> Option<Self>;
}
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
@@ -58,10 +55,7 @@ fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self {
Box::<[u8]>::from(slice.into())
}
fn zeroed(
size: Size,
_align: Align,
) -> Option<Self> {
fn zeroed(size: Size, _align: Align) -> Option<Self> {
let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes_usize()).ok()?;
// SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]>
let bytes = unsafe { bytes.assume_init() };