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>
impl<'a> PageRef<'a>
Sourcepub fn as_bytes(&self) -> &'a [u8; 4096]
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.
Sourcepub fn to_owned_page(&self) -> Page
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).