Skip to main content

PageRef

Struct PageRef 

Source
pub struct PageRef<'a> { /* private fields */ }
Expand description

A borrowed view of a cached or WAL-staged page.

PageRef is the return type of Pager::read_page. It carries a shared reference to the page’s bytes that lives no longer than the immutable borrow of the pager that produced it — so the borrow checker forbids holding a PageRef across any mutating call on the same pager (write, commit, checkpoint, alloc, free).

§Allocation contract

Construction of a PageRef performs no heap allocation on cache hits or WAL-overlay hits: the bytes are already resident in memory and PageRef is a thin wrapper around a &[u8; PAGE_SIZE]. On a cache miss the read-through path issues one pread and inserts the page into the cache, after which the PageRef borrows that cache frame.

§Examples

let view = p.read_page(a)?;
let header_byte = view.as_bytes()[0];
// `view` must be dropped (or moved) before the next p.write_page(...).

Implementations§

Source§

impl<'a> PageRef<'a>

Source

pub fn page_id(&self) -> PageId

The page id this view was read for.

Source

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

The page’s raw bytes. Includes the per-page CRC32C trailer in its last PAGE_TRAILER_SIZE bytes; callers that want only the payload should slice off the trailer themselves.

Source

pub fn to_owned_page(&self) -> Page

Clone the underlying page into a fresh owned Page. This allocates; only call it when an owned buffer is genuinely required (e.g. to mutate before a subsequent write_page).

Trait Implementations§

Source§

impl<'a> Debug for PageRef<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PageRef<'a>

§

impl<'a> RefUnwindSafe for PageRef<'a>

§

impl<'a> Send for PageRef<'a>

§

impl<'a> Sync for PageRef<'a>

§

impl<'a> Unpin for PageRef<'a>

§

impl<'a> UnsafeUnpin for PageRef<'a>

§

impl<'a> UnwindSafe for PageRef<'a>

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> 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, 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