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>
impl<'a> DataStackRegisterAccess<'a>
Sourcepub fn type_hash_layout(&self) -> (TypeHash, Layout)
pub fn type_hash_layout(&self) -> (TypeHash, Layout)
Returns type and layout together, reading the header only once.
Sourcepub fn read<T>(&'a self) -> Option<&'a T>where
T: 'static,
pub fn read<T>(&'a self) -> Option<&'a T>where
T: 'static,
Borrows the stored value, or returns None when the register is empty
or holds another type.
Sourcepub fn write<T>(&'a mut self) -> Option<&'a mut T>where
T: 'static,
pub fn write<T>(&'a mut self) -> Option<&'a mut T>where
T: 'static,
Borrows the stored value mutably, or returns None when the register
is empty or holds another type.
Sourcepub fn take<T>(&mut self) -> Option<T>where
T: 'static,
pub fn take<T>(&mut self) -> Option<T>where
T: 'static,
Moves the value out and leaves the register empty.
Returns None when the register is empty or holds another type.
Sourcepub fn free(&mut self) -> bool
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.
Sourcepub fn set<T>(&mut self, value: T)where
T: Finalize + 'static,
pub fn set<T>(&mut self, value: T)where
T: Finalize + 'static,
Moves a value into the register, dropping whatever was there.
Does nothing when T is not the type the register was declared with.
Sourcepub fn move_to(&mut self, other: &mut DataStackRegisterAccess<'a>)
pub fn move_to(&mut self, other: &mut DataStackRegisterAccess<'a>)
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.