Skip to main content

DataStackRegisterAccess

Struct DataStackRegisterAccess 

Source
pub struct DataStackRegisterAccess<'a> { /* private fields */ }
Expand description

Handle to one register slot, taken with DataStack::access_register.

A register has a fixed type chosen when it was pushed, and is either empty or full. Reads and takes check the requested type against the register type and return None on a mismatch.

Implementations§

Source§

impl<'a> DataStackRegisterAccess<'a>

Source

pub fn type_hash(&self) -> TypeHash

Returns the type this register slot was declared with.

Source

pub fn layout(&self) -> Layout

Returns the memory layout of the register slot.

Source

pub fn type_hash_layout(&self) -> (TypeHash, Layout)

Returns type and layout together, reading the header only once.

Source

pub fn has_value(&self) -> bool

Returns true when the register currently holds a value.

Source

pub fn read<T: 'static>(&'a self) -> Option<&'a T>

Borrows the stored value, or returns None when the register is empty or holds another type.

Source

pub fn write<T: 'static>(&'a mut self) -> Option<&'a mut T>

Borrows the stored value mutably, or returns None when the register is empty or holds another type.

Source

pub fn take<T: 'static>(&mut self) -> Option<T>

Moves the value out and leaves the register empty.

Returns None when the register is empty or holds another type.

Source

pub fn free(&mut self) -> bool

Drops the stored value in place and leaves the register empty.

Returns false when there was nothing to drop.

Source

pub fn set<T: Finalize + 'static>(&mut self, value: T)

Moves a value into the register, dropping whatever was there.

Does nothing when T is not the type the register was declared with.

Source

pub fn move_to(&mut self, other: &mut Self)

Moves this register value into other, leaving this one empty.

Does nothing when the two registers differ in type or layout, or when they are the same slot.

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> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Drops the value stored at data in place. 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, 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.