Skip to main content

SelfRef

Struct SelfRef 

Source
pub struct SelfRef<T: 'static> { /* private fields */ }
Expand description

A decoded value T that may borrow from its own backing storage.

Transports decode into storage they own (heap buffer, VarSlot, mmap). SelfRef keeps that storage alive so T can safely borrow from it.

Uses ManuallyDrop + custom Drop to guarantee drop order: value is dropped before backing, so borrowed references in T remain valid through T’s drop.

Implementations§

Source§

impl<T: 'static> SelfRef<T>

Source

pub fn try_new<E>( backing: Backing, builder: impl FnOnce(&'static [u8]) -> Result<T, E>, ) -> Result<Self, E>

Construct a SelfRef from backing storage and a builder.

The builder receives a &'static [u8] view of the backing bytes — sound because the backing is heap-allocated (stable address) and dropped after the value.

Source

pub fn new(backing: Backing, builder: impl FnOnce(&'static [u8]) -> T) -> Self

Infallible variant of try_new.

Source

pub fn owning(backing: Backing, value: T) -> Self

Wrap an owned value that does NOT borrow from backing.

No variance check — the value is fully owned. The backing is kept alive but the value doesn’t reference it. Useful for in-memory transports (MemoryLink) where no deserialization occurs.

Source

pub fn try_repack<U: 'static, E>( self, f: impl FnOnce(T, &'static [u8]) -> Result<U, E>, ) -> Result<SelfRef<U>, E>

Transform the contained value, keeping the same backing storage.

Useful for projecting through wrapper types: SelfRef<Frame<T>>SelfRef<T> by extracting the inner item.

The closure receives the old value by move and returns the new value. Any references the new value holds into the backing storage (inherited from fields of T) remain valid — the backing is preserved. Like try_map, but the closure also receives a &'static [u8] view of the backing bytes, so the new value U can borrow from them.

Source

pub fn try_map<U: 'static, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<SelfRef<U>, E>

Source

pub fn map<U: 'static>(self, f: impl FnOnce(T) -> U) -> SelfRef<U>

Trait Implementations§

Source§

impl<T: 'static> Deref for SelfRef<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: 'static> Drop for SelfRef<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SelfRef<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for SelfRef<T>

§

impl<T> Send for SelfRef<T>
where T: Send,

§

impl<T> Sync for SelfRef<T>
where T: Sync,

§

impl<T> Unpin for SelfRef<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for SelfRef<T>
where T: UnsafeUnpin,

§

impl<T> !UnwindSafe for SelfRef<T>

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,