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 const fn byte_offset(self) -> u64
pub const fn byte_offset(self) -> u64
Byte offset at which this page begins in the database file.
Computed as id * PAGE_SIZE with u64 arithmetic; overflow is
not possible for any realistic file (u64::MAX / PAGE_SIZE
pages is ~4.5 EiB).
Trait Implementations§
Source§impl Ord for PageId
impl Ord for PageId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for PageId
impl PartialOrd for PageId
impl Copy for PageId
impl Eq for PageId
impl StructuralPartialEq for PageId
Auto Trait Implementations§
impl Freeze for PageId
impl RefUnwindSafe for PageId
impl Send for PageId
impl Sync for PageId
impl Unpin for PageId
impl UnsafeUnpin for PageId
impl UnwindSafe for PageId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more