Add mentioned from_raw_bytes constructor

This commit is contained in:
Rune Tynan 2023-02-13 23:16:56 -05:00
parent 6f407d67b8
commit b2455dc91c
No known key found for this signature in database
GPG Key ID: 7ECC932F8B2C731E

View File

@ -270,6 +270,23 @@ pub fn subrange(self, subrange: AllocRange) -> AllocRange {
// The constructors are all without extra; the extra gets added by a machine hook later.
impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
/// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support
pub fn from_raw_bytes<'a>(
bytes: Bytes,
align: Align,
mutability: Mutability,
) -> Self {
let size = Size::from_bytes(bytes.len());
Self {
bytes,
provenance: ProvenanceMap::new(),
init_mask: InitMask::new(size, true),
align,
mutability,
extra: (),
}
}
/// Creates an allocation initialized by the given bytes
pub fn from_bytes<'a>(
slice: impl Into<Cow<'a, [u8]>>,