mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 15:36:08 +00:00
add Mmap::assume_init
to convert Mmap<MaybeUninit<T>> to Mmap<T> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
ffbf58cad3
commit
9da1062f82
@ -1,6 +1,7 @@
|
|||||||
//! Memory mapping helpers.
|
//! Memory mapping helpers.
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::{io, mem, ptr};
|
use std::{io, mem, ptr};
|
||||||
|
|
||||||
@ -87,3 +88,20 @@ impl<'a, T> IntoIterator for &'a Mmap<T> {
|
|||||||
<&'a [T] as IntoIterator>::into_iter(self)
|
<&'a [T] as IntoIterator>::into_iter(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Mmap<MaybeUninit<T>> {
|
||||||
|
/// Converts to `Mmap<T>`.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// It is up to the caller to ensure this is safe, see
|
||||||
|
/// [`MaybeUninit::assume_init`](std::mem::MaybeUninit::assume_init).
|
||||||
|
pub unsafe fn assume_init(self) -> Mmap<T> {
|
||||||
|
let out = Mmap {
|
||||||
|
data: self.data as *mut T,
|
||||||
|
len: self.len,
|
||||||
|
};
|
||||||
|
std::mem::forget(self);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user