pub struct PageId(/* private fields */);Expand description
Identifier of a page in a database file.
PageId is NonZeroU64 so the on-disk value 0 can be used as a
sentinel “no page” marker (e.g. the freelist-empty case). This
follows power-of-ten Rule 5: encode the invariant in the type so
neither the compiler nor a reviewer has to remember it.
Implementations§
Source§impl PageId
impl PageId
Sourcepub const fn new(raw: u64) -> Option<Self>
pub const fn new(raw: u64) -> Option<Self>
Construct a PageId from a raw u64. Returns None if raw
is 0. Prefer this over the unsafe NonZeroU64::new_unchecked
(Rule 8: no unsafe outside the platform layer).
Sourcepub const fn from_nonzero(nz: NonZeroU64) -> Self
pub const fn from_nonzero(nz: NonZeroU64) -> Self
Construct a PageId from a NonZeroU64. Total function.
Sourcepub fn byte_offset(self, feature_flags: u32) -> u64
pub fn byte_offset(self, feature_flags: u32) -> u64
Byte offset at which this page begins in the database file,
for a file with the given feature_flags.
#28: the offset is stride-aware. Encrypted files (encryption
bit set in feature_flags) use a 4136-byte physical stride
for pages 1..N, so a fixed id * PAGE_SIZE computation is
wrong for them. This delegates to physical_offset_for,
the same helper the pager uses for its real reads/writes
(Pager::physical_offset), so the two never diverge. Page 0
is always at offset 0. Pass 0 for plaintext (unencrypted)
files.