Skip to content

Commit

Permalink
refactor: add deep Clone to FatPage
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier authored and pepyakin committed Jan 2, 2025
1 parent 4e36916 commit aa13633
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nomt/src/io/page_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Page {
///
/// Unlike [`Page`], this type handles deallocation for you upon dropping. It also provides a safe
/// way to access the contents of the page. However, the price for this convenience is that it is
/// heavier than the bare page type and it doesn't allow cloning.
/// heavier than the bare page type and cloning performs a deep copy.
pub struct FatPage {
page_pool: PagePool,
page: Page,
Expand All @@ -86,6 +86,14 @@ impl FatPage {
}
}

impl Clone for FatPage {
fn clone(&self) -> Self {
let mut new_page = self.page_pool.alloc_fat_page();
new_page.copy_from_slice(&*self);
new_page
}
}

impl Deref for FatPage {
type Target = [u8];

Expand Down

0 comments on commit aa13633

Please sign in to comment.