Struct Slots

Source
pub struct Slots<'a>(/* private fields */);

Implementations§

Source§

impl<'a> Slots<'a>

Source

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.

Source

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.

Source

pub fn new_nested_ro<'b>(&'b self) -> Slots<'b>
where 'a: 'b,

Create a new nested read-only slots instance

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn reset(&mut self)

Reset any changes that might have been done on this level

Trait Implementations§

Source§

impl<'a> Debug for Slots<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for Slots<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Slots<'a>

§

impl<'a> RefUnwindSafe for Slots<'a>

§

impl<'a> Send for Slots<'a>

§

impl<'a> Sync for Slots<'a>

§

impl<'a> Unpin for Slots<'a>

§

impl<'a> !UnwindSafe for Slots<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more