Use .map()

This commit is contained in:
bjorn3
2021-05-11 17:11:43 +02:00
parent bb769afe6b
commit 05b9037bbb

View File

@@ -42,20 +42,15 @@ impl PtrLen {
fn with_size(size: usize) -> io::Result<Self> { fn with_size(size: usize) -> io::Result<Self> {
let page_size = region::page::size(); let page_size = region::page::size();
let alloc_size = round_up_to_page_size(size, page_size); let alloc_size = round_up_to_page_size(size, page_size);
let map = MmapMut::map_anon(alloc_size); MmapMut::map_anon(alloc_size).map(|mut mmap| {
// The order here is important; we assign the pointer first to get
match map { // around compile time borrow errors.
Ok(mut map) => { Ok(Self {
// The order here is important; we assign the pointer first to get ptr: mmap.as_mut_ptr(),
// around compile time borrow errors. map: Some(mmap),
Ok(Self { len: alloc_size,
ptr: map.as_mut_ptr(), })
map: Some(map), })
len: alloc_size,
})
}
Err(e) => Err(e),
}
} }
#[cfg(all(not(target_os = "windows"), not(feature = "selinux-fix")))] #[cfg(all(not(target_os = "windows"), not(feature = "selinux-fix")))]