Skip to main content

NonNullOffset

Struct NonNullOffset 

Source
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

Source

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).

Source

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.

Source

pub const fn get(self) -> Offset

Widen back to the base Offset (never NULL) — the NonZeroU64::get analogue.

Source

pub const fn as_u64(self) -> u64

The raw non-zero byte address, skipping the Offset wrapper.

Source

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).

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for NonNullOffset

Source§

impl Debug for NonNullOffset

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for NonNullOffset

Source§

impl From<NonNullOffset> for Offset

Source§

fn from(o: NonNullOffset) -> Offset

Widen to the nullable base type — the From<NonZeroU64> for u64 analogue.

Source§

impl From<NonNullOffset> for u64

Source§

fn from(o: NonNullOffset) -> u64

Converts to this type from the input type.
Source§

impl Hash for NonNullOffset

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NonNullOffset

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for NonNullOffset

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for NonNullOffset

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for NonNullOffset

Source§

impl TryFrom<Offset> for NonNullOffset

Source§

fn try_from(offset: Offset) -> Result<Self, NullOffsetError>

Refine to non-null, failing on NULL — the TryFrom<u64> for NonZeroU64 analogue.

Source§

type Error = NullOffsetError

The type returned in the event of a conversion error.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.