pub struct Slots<'a>(/* private fields */);
Implementations§
Source§impl<'a> Slots<'a>
impl<'a> Slots<'a>
Sourcepub fn new<I>(slots: I) -> Self
pub fn new<I>(slots: I) -> Self
Create a new instance from a hashmap containing existing slots.
Only slots that are present in the input can be modified. The only exception is slots for
owners created during runtime and initialized with Self::add_new_contract()
.
“Empty” slots must still have a value in the form of an empty SharedAlignedBuffer
.
Sourcepub fn new_nested_rw<'b>(&'b mut self) -> Option<Slots<'b>>where
'a: 'b,
pub fn new_nested_rw<'b>(&'b mut self) -> Option<Slots<'b>>where
'a: 'b,
Create a new nested read-write slots instance.
Nested instance will integrate its changes into the parent slot when dropped (or changes can
be reset with Self::reset()
).
Returns None
when attempted on read-only instance.
Sourcepub fn new_nested_ro<'b>(&'b self) -> Slots<'b>where
'a: 'b,
pub fn new_nested_ro<'b>(&'b self) -> Slots<'b>where
'a: 'b,
Create a new nested read-only slots instance
Sourcepub fn add_new_contract(&mut self, owner: Address) -> bool
pub fn add_new_contract(&mut self, owner: Address) -> bool
Add a new contract that didn’t exist before.
In contrast to contracts in Self::new()
, this contract will be allowed to have any slots
related to it being modified.
Returns false
if a contract already exits in a map, which is also considered as an access
violation.
Sourcepub fn get_code(&self, owner: Address) -> Option<SharedAlignedBuffer>
pub fn get_code(&self, owner: Address) -> Option<SharedAlignedBuffer>
Get code for owner
.
The biggest difference from Self::use_ro()
is that the slot is not marked as used,
instead the current code is cloned and returned.
Returns None
in case of access violation or if code is missing.
Sourcepub fn use_ro(&mut self, slot_key: SlotKey) -> Option<&SharedAlignedBuffer>
pub fn use_ro(&mut self, slot_key: SlotKey) -> Option<&SharedAlignedBuffer>
Read-only access to a slot with specified owner and contract, marks it as used.
Returns None
in case of access violation.
Sourcepub fn use_rw(
&mut self,
slot_key: SlotKey,
capacity: u32,
) -> Option<(SlotIndex, &mut OwnedAlignedBuffer)>
pub fn use_rw( &mut self, slot_key: SlotKey, capacity: u32, ) -> Option<(SlotIndex, &mut OwnedAlignedBuffer)>
Read-write access to a slot with specified owner and contract, marks it as used.
The returned slot is no longer accessible through Self::use_ro()
or Self::use_rw()
during the lifetime of this Slot
instance (and can be safely turned into a pointer). The
only way to get another mutable reference is to call Self::access_used_rw()
.
Returns None
in case of access violation.
Sourcepub fn access_used_rw(
&mut self,
slot_index: SlotIndex,
) -> Option<&mut OwnedAlignedBuffer>
pub fn access_used_rw( &mut self, slot_index: SlotIndex, ) -> Option<&mut OwnedAlignedBuffer>
Read-write access to a slot with specified owner and contract, that is currently marked as
used due to earlier call to Self::use_rw()
.
NOTE: Calling this method means that any pointers that might have been stored to the result
of Self::use_rw()
call are now invalid!
Returns None
in case of access violation.