From 1b9a5558f5fc0c49c4d54b9135007a6bfc0c0336 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Mon, 6 Sep 2021 11:47:09 -0400 Subject: [PATCH] Remove Page::copy() The approach in `Pages::copy()` is better. Signed-off-by: Nathaniel McCallum --- src/page.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/page.rs b/src/page.rs index a3c5d36..420e62a 100644 --- a/src/page.rs +++ b/src/page.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 use core::borrow::{Borrow, BorrowMut}; -use core::mem::{align_of, align_of_val, size_of, size_of_val}; use core::ops::{Deref, DerefMut}; /// A single page of memory @@ -77,26 +76,4 @@ impl Page { pub const fn zeroed() -> Self { Self([[0; 32]; 16]) } - - /// Copy a value into the start of a page - /// - /// All unused bytes are zero. - /// - /// # Panics - /// - /// This function panics if any of these constraints are false: - /// 1. `size_of::() >= size_of_val(&value)` - /// 2. `align_of::() >= align_of_val(&value)` - /// 3. `align_of::() % align_of_val(&value) == 0` - pub fn copy(value: T) -> Page { - assert!(size_of::() >= size_of_val(&value)); - assert!(align_of::() >= align_of_val(&value)); - assert!(align_of::() % align_of_val(&value) == 0); - - let mut pages = [Page::default()]; - let bytes = unsafe { pages.align_to_mut::().1 }; - let typed = unsafe { bytes.align_to_mut().1 }; - typed[0] = value; - pages[0] - } }