pub struct NonNullOffset(/* private fields */);Expand description
An Offset statically guaranteed non-null — a resolved, real target
address (a control-block back-pointer, a live child, a refcount counter). Carries
the not-null invariant in the type, so a consumer that needs a genuine target
takes a NonNullOffset and the null check happens once, at the boundary, via
Offset::to_non_null — not re-checked at every deref.
Backed by NonZeroU64, so Option<NonNullOffset> is the same 8 bytes as an
Offset (the 0 bit-pattern is the None niche). Not Pod:
0 is an invalid bit pattern, so it is an in-memory refinement, never a wire type —
the on-disk form is always the nullable Offset.
Implementations§
Source§impl NonNullOffset
impl NonNullOffset
Sourcepub const fn new(offset: Offset) -> Option<Self>
pub const fn new(offset: Offset) -> Option<Self>
Refine an Offset to non-null, or None if it is NULL —
the NonZeroU64::new analogue (Offset is the base type, as u64 is
NonZeroU64’s).
Sourcepub const unsafe fn new_unchecked(offset: Offset) -> Self
pub const unsafe fn new_unchecked(offset: Offset) -> Self
Refine an Offset to non-null without checking — the
NonZeroU64::new_unchecked analogue.
§Safety
offset must not be NULL. A null offset here is instant
undefined behaviour: NonNullOffset is NonZeroU64-backed, and a zero
NonZeroU64 violates its niche.
Sourcepub const fn get(self) -> Offset
pub const fn get(self) -> Offset
Widen back to the base Offset (never NULL) — the
NonZeroU64::get analogue.
Sourcepub fn checked_add(self, delta: u64) -> Result<NonNullOffset>
pub fn checked_add(self, delta: u64) -> Result<NonNullOffset>
This address advanced by delta bytes, rejecting overflow. The result stays
non-null (a non-zero base plus a non-negative delta cannot wrap to 0 without
overflowing, which is rejected).
Sourcepub fn from_range(range: BStackRange) -> Option<NonNullOffset>
pub fn from_range(range: BStackRange) -> Option<NonNullOffset>
The range’s start as a non-null offset, or None at offset 0.
The direct form of Offset::from(range).to_non_null().
A From<BStackRange> for Option<NonNullOffset> impl is disallowed by the
orphan rule (Option is not a local type), so this is a named constructor.
Sourcepub fn from_slice(slice: BStackSlice<'_>) -> Option<NonNullOffset>
pub fn from_slice(slice: BStackSlice<'_>) -> Option<NonNullOffset>
The slice’s start as a non-null offset, or None at offset 0.
The direct form of Offset::from(slice).to_non_null();
a named constructor for the same orphan-rule reason as from_range.
Sourcepub fn from_field(off: u64) -> Result<NonNullOffset>
pub fn from_field(off: u64) -> Result<NonNullOffset>
Refine a raw byte offset that is non-null by construction — an on-disk
field address past the block header (a refcount / control counter, a live
child slot) — erroring rather than panicking on the 0 that only a corrupt
or forged base could produce. The bridge from the u64 that offset
arithmetic ([checked_off], add_off) yields to
the NonNullOffset the counter ops (crate::io_core::refcount) require.
Trait Implementations§
Source§impl Clone for NonNullOffset
impl Clone for NonNullOffset
impl Copy for NonNullOffset
Source§impl Debug for NonNullOffset
impl Debug for NonNullOffset
impl Eq for NonNullOffset
Source§impl From<NonNullOffset> for Offset
impl From<NonNullOffset> for Offset
Source§fn from(o: NonNullOffset) -> Offset
fn from(o: NonNullOffset) -> Offset
Widen to the nullable base type — the From<NonZeroU64> for u64 analogue.