Skip to main content

PageHandle

Enum PageHandle 

Source
pub enum PageHandle {
    Shared(Arc<Page>),
    Owned(Page),
}
Expand description

Owning handle to a page returned by ReaderSnapshot::read_page.

#81: read_page used to return an owned Page (a 4 KiB body clone) on every call, including the common frozen-view hit. A point read descends catalog + primary and an index lookup descends two trees, so each op paid 3-5 such 4 KiB copies. PageHandle removes the copy on the hot path:

  • PageHandle::Shared — frozen-view hit. Holds an Arc<Page> cloned from the snapshot’s view (a refcount bump, no body copy). Sound because committed pages are immutable: a new version is a fresh Arc under the same PageId, never an in-place mutation of a shared Arc (see frozen_view).
  • PageHandle::Owned — disk / cache miss. Holds the freshly read, checksum-verified Page produced by the existing read_main_file_page / read_cache_or_main (read_through) path; integrity behaviour is unchanged.

Concrete enum, not dyn (Rule 9). Both arms are a single pointer (Arc<Page> and Page’s Box<[u8; PAGE_SIZE]>), so the variants are balanced and clippy::large_enum_variant does not fire.

Variants§

§

Shared(Arc<Page>)

Frozen-view hit — shares the snapshot’s Arc<Page> with no 4 KiB body clone.

§

Owned(Page)

Disk / cache miss — owns the checksum-verified page bytes.

Implementations§

Source§

impl PageHandle

Source

pub fn as_bytes(&self) -> &[u8; 4096]

Borrow the page’s raw bytes for decoding, without copying.

The match over both arms is total — no Result, no unwrap/expect (Rule 7): every PageHandle always holds a readable page in exactly one of its two arms. Callers that only need to decode (e.g. BTree::get_via_snapshot, Catalog::lookup_via_snapshot) should keep the PageHandle alive for the duration of the borrow and call this.

Source

pub fn into_page(self) -> Page

Consume the handle and produce an owned Page.

The Shared arm clones the body exactly once (only when an owned page is genuinely required, e.g. the public crate::ReadTxn::read_page whose pager lock guard cannot outlive the call); the Owned arm moves with no copy. This is the only place the hot-path frozen-view clone is paid, and only for callers that ask for ownership.

Trait Implementations§

Source§

impl Clone for PageHandle

Source§

fn clone(&self) -> PageHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PageHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V