Expand description
An immovable owned value in borrowed backing memory.
Implementations
sourceimpl<'a, T: DropRaw + ?Sized> Val<'a, T>
impl<'a, T: DropRaw + ?Sized> Val<'a, T>
sourcepub unsafe fn new_unchecked(ptr: *mut T) -> Self
pub unsafe fn new_unchecked(ptr: *mut T) -> Self
Creates a new Val from an exclusively owned pointer.
Safety
ptrmust be non-null, properly aligned, and valid for reading, writing, and dropping.ptrmust not alias any other accessible references for'a.- The value pointed to by
ptrmust be initialized and immovable.
sourcepub unsafe fn from_slot_unchecked(slot: Slot<'a, T>) -> Self
pub unsafe fn from_slot_unchecked(slot: Slot<'a, T>) -> Self
Creates a new Val from an initialized Slot.
Safety
The value pointed to by slot must be initialized, valid for dropping,
and immovable.
sourcepub fn leak(v: Self) -> Mut<'a, T>
pub fn leak(v: Self) -> Mut<'a, T>
Consumes the Val and leaks its value, returning a mutable reference
&'a mut T.
This function is mainly useful for data that lives for as long as its
backing memory. Dropping the returned reference will cause a memory
leak. If this is not acceptable, then the reference should first be
wrapped with the Val::new_unchecked function, producing a Val.
This Val can then be dropped which will properly destroy T.
Note: this is an associated function, which means that you have to call
it as Val::leak(x) instead of x.leak(). This is so that there is no
conflict with a method named leak on the value type.
sourcepub fn read(this: Self) -> Twhere
T: Sized + Unpin,
pub fn read(this: Self) -> Twhere
T: Sized + Unpin,
Consumes the Val and returns the value it contained.
Note: this is an associated function, which means that you have to call
it as Val::read(this) instead of this.read(). This is so that there
is no conflict with a method on the inner type.
sourcepub fn read_unsized(this: Self, slot: Slot<'_, T>)where
T: Pointee + Unpin,
<T as Pointee>::Metadata: Metadata<T>,
pub fn read_unsized(this: Self, slot: Slot<'_, T>)where
T: Pointee + Unpin,
<T as Pointee>::Metadata: Metadata<T>,
Consumes the Val and moves it into the given Slot.
Note: this is an associated function, which means that you have to call
it as Val::read_unsized(this, slot) instead of
this.read_unsized(slot). This is so that there is no conflict with a
method on the inner type.
Panics
Panics if slot does not have the same metadata as this.
sourcepub unsafe fn read_unsized_unchecked(this: Self, slot: Slot<'_, T>)where
T: Pointee + Unpin,
<T as Pointee>::Metadata: Metadata<T>,
pub unsafe fn read_unsized_unchecked(this: Self, slot: Slot<'_, T>)where
T: Pointee + Unpin,
<T as Pointee>::Metadata: Metadata<T>,
Consumes the Val and moves it into the given Slot.
Note: this is an associated function, which means that you have to call
it as Val::read_unsized_unchecked(this, slot) instead of
this.read_unsized_unchecked(slot). This is so that there is no
conflict with a method on the inner type.
Safety
slot must have the same metadata as this.
sourcepub fn forget(this: Self) -> Slot<'a, T>
pub fn forget(this: Self) -> Slot<'a, T>
Forgets the contained value, returning a Slot of the underlying
memory.