From acfc5c5d21b332a3a8ed339be54c1f1c2d9c7f86 Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Tue, 13 Jul 2021 17:04:49 -0700 Subject: [PATCH] add another Page constructor, which copies bytes --- snapfile/src/page.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/snapfile/src/page.rs b/snapfile/src/page.rs index 625dd64b8f..08a5a9afc6 100644 --- a/snapfile/src/page.rs +++ b/snapfile/src/page.rs @@ -1,6 +1,16 @@ /// A single 8KB page. pub struct Page(pub Box<[u8; 8192]>); +impl Page { + /// Create a page by copying bytes from another slice. + /// + /// This is a copy, not a move. If the caller already has + /// an owned array then `From<[u8; 8192]>` can be used instead. + pub fn copy_slice(x: &[u8; 8192]) -> Self { + Page(Box::new(x.clone())) + } +} + impl Default for Page { fn default() -> Self { Page(Box::new([0u8; 8192]))