mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Format
This commit is contained in:
parent
3a87a18857
commit
f26b0a2948
@ -42,10 +42,7 @@ pub trait AllocBytes:
|
|||||||
|
|
||||||
/// Create a zeroed `AllocBytes` of the specified size and alignment;
|
/// Create a zeroed `AllocBytes` of the specified size and alignment;
|
||||||
/// call the callback error handler if there is an error in allocating the memory.
|
/// call the callback error handler if there is an error in allocating the memory.
|
||||||
fn zeroed(
|
fn zeroed(size: Size, _align: Align) -> Option<Self>;
|
||||||
size: Size,
|
|
||||||
_align: Align,
|
|
||||||
) -> Option<Self>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
|
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
|
||||||
@ -58,10 +55,7 @@ impl AllocBytes for Box<[u8]> {
|
|||||||
Box::<[u8]>::from(slice.into())
|
Box::<[u8]>::from(slice.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zeroed(
|
fn zeroed(size: Size, _align: Align) -> Option<Self> {
|
||||||
size: Size,
|
|
||||||
_align: Align,
|
|
||||||
) -> Option<Self> {
|
|
||||||
let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes_usize()).ok()?;
|
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]>
|
// SAFETY: the box was zero-allocated, which is a valid initial value for Box<[u8]>
|
||||||
let bytes = unsafe { bytes.assume_init() };
|
let bytes = unsafe { bytes.assume_init() };
|
||||||
|
Loading…
Reference in New Issue
Block a user