Skip to main content

SharedUmbraPointer

Struct SharedUmbraPointer 

Source
pub struct SharedUmbraPointer<T: Copy + 'static> {
    pub target: OffsetPtr<T>,
    pub prefix: u32,
    /* private fields */
}
Expand description

16-byte cross-process content-prefixed pointer.

Layout is fixed and PoD so SIMD scans over an array see a stable prefix-byte position.

offset 0   : OffsetPtr<T>     (u32 index; NIL = u32::MAX)
offset 4   : u32 prefix
offset 8   : u8 ext_tag       (0 = unset; 1..=255 = registered)
offset 9   : [u8; 7] ext_payload  (interpretation per tag)
offset 16  : end

§User-addressable extension bytes

Bytes 8..16 are a TAG (1 byte) + PAYLOAD (7 bytes) that callers can use to attach typed metadata to the pointer. Access via the UmbraExtension trait + set_ext / ext methods:

  • Guard 1 (compile-time size): set_ext<E> and ext<E> both monomorphize a const-assertion that size_of::<E>() <= 7. Larger types fail to compile.
  • Guard 2 (runtime tag): each UmbraExtension declares a unique TAG: u8 constant. ext<E>() returns None if the pointer’s tag does not match E::TAG, preventing two consumers from interpreting the same bytes differently.
  • Guard 3 (type bound): E: Copy + 'static ensures no Drop side effects and no lifetimes to manage.

Fields§

§target: OffsetPtr<T>

Index of the target slot in some SharedRegion<T>. The region itself is held by the caller; this pointer is just the cross-process-stable address.

§prefix: u32

4-byte content prefix derived from the target’s bytes (or a 4-byte hash). Constant for the lifetime of the pointer.

Implementations§

Source§

impl<T: Copy + 'static> SharedUmbraPointer<T>

Source

pub const SIGNATURE: AxisMask

Direction signature of SharedUmbraPointer<T>. Engages the K_content_prefix axis (4-byte prefix stored at slot for short-circuit equality before MMF deref).

Source

pub const NIL: Self

NIL sentinel: target is OffsetPtr::NIL and prefix is 0; extension tag is 0 (unset). Equivalent to a freshly-zeroed 16-byte slot.

Source

pub const fn new(target: OffsetPtr<T>, prefix: u32) -> Self

Construct from an existing region-allocated OffsetPtr and a caller-computed prefix. Extension is unset (tag=0).

Source

pub fn set_ext<E: UmbraExtension>(&mut self, value: E)

Write a typed extension. Sets the tag to E::TAG and copies the value bytes into the payload. Caller guarantees E::TAG is globally unique.

Source

pub unsafe fn ext<E: UmbraExtension>(&self) -> Option<E>

Read a typed extension. Returns None if no extension is set (tag=0) OR if the stored tag does not match E::TAG.

§Safety

Even with tag validation, this is unsafe because the tag-uniqueness contract is on the caller. Two UmbraExtension implementations sharing a TAG value will silently misinterpret each other’s payloads. The payload bytes must also be a valid representation of E (relevant for enums with restricted discriminants).

Source

pub fn clear_ext(&mut self)

Clear the extension. Tag and payload set to 0.

Source

pub fn ext_tag(&self) -> u8

The current extension tag (0 = unset).

Source

pub fn ext_payload_raw(&self) -> &[u8; 7]

Raw byte access to the extension payload. Use this for debugging or when interfacing with untyped consumers.

Source

pub fn from_region_alloc_content_prefix( region: &SharedRegion<T>, value: T, ) -> Result<Self, RegionError>

Allocate value in region and build a pointer whose prefix is the first 4 bytes of the in-memory representation of T (little-endian native). Useful when T’s first bytes are a meaningful key field (row IDs, packet headers).

Source

pub fn from_region_alloc_hash_prefix( region: &SharedRegion<T>, value: T, ) -> Result<Self, RegionError>
where T: Hash,

Allocate value in region and build a pointer whose prefix is the low 32 bits of std::hash::DefaultHasher applied to value. Near-perfect rejection rate; requires T: Hash.

Source

pub fn from_region_alloc( region: &SharedRegion<T>, value: T, prefix: u32, ) -> Result<Self, RegionError>

Allocate value in region and build a pointer with an explicit caller-supplied prefix.

Source

pub fn is_nil(&self) -> bool

True when target is NIL. Prefix may still be non-zero.

Source

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

Prefix-only comparison. Single in-register check; does NOT touch the region MMF. Use as the first step in a staged equality check.

Source

pub fn matches_prefix(&self, query: u32) -> bool

Compare against a literal query prefix. Same semantics as prefix_eq against a constructed SharedUmbraPointer.

Source

pub fn resolve(&self, region: &SharedRegion<T>) -> Result<T, RegionError>

Resolve the target through region. Costs one MMF read. Only call after a successful prefix check unless you really need the value.

Trait Implementations§

Source§

impl<T: Copy + 'static> Clone for SharedUmbraPointer<T>

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<T: Copy + 'static> Copy for SharedUmbraPointer<T>

Source§

impl<T: Debug + Copy + 'static> Debug for SharedUmbraPointer<T>

Source§

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

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

impl<T: Copy + 'static> Default for SharedUmbraPointer<T>

Source§

fn default() -> Self

NIL pointer with zero prefix. Zero-bytes representation, safe to write into freshly-zeroed MMF storage.

Source§

impl<T: Copy + 'static> Eq for SharedUmbraPointer<T>

Source§

impl<T: Copy + 'static> PartialEq for SharedUmbraPointer<T>

Source§

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

Full equality: same target AND same prefix. Use prefix_eq for the fast-path prefix-only check.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.