#[repr(C)]pub struct State;
Implementations§
Source§impl State
impl State
Sourcepub fn initialize(
env: &mut Env<'_>,
(address, contract_state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>),
state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
) -> Result<(), ContractError>
pub fn initialize( env: &mut Env<'_>, (address, contract_state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>), state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>
Initialize state.
Similar to State::write()
, but returns error if the state is not empty.
Sourcepub fn write(
env: &mut Env<'_>,
(address, state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>),
new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
) -> Result<(), ContractError>
pub fn write( env: &mut Env<'_>, (address, state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>), new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>
Write state.
Only direct caller is allowed to write its own state for security reasons.
Sourcepub fn compare_and_write(
env: &mut Env<'_>,
(address, state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>),
old_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
) -> Result<Bool, ContractError>
pub fn compare_and_write( env: &mut Env<'_>, (address, state): (&Address, &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>), old_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, new_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<Bool, ContractError>
Compare state with a given old state and write new state if old state matches.
Only direct caller is allowed to write its own state for security reasons.
Returns boolean indicating whether write happened or not.
Sourcepub fn read(
contract_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
state: &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>,
) -> Result<(), ContractError>
pub fn read( contract_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, state: &mut VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Result<(), ContractError>
Read state
Sourcepub fn is_empty(
contract_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>,
) -> Bool
pub fn is_empty( contract_state: &VariableBytes<RECOMMENDED_STATE_CAPACITY>, ) -> Bool
Check if the state is empty
Trait Implementations§
Source§impl Contract for State
impl Contract for State
Source§const MAIN_CONTRACT_METADATA: &[u8]
const MAIN_CONTRACT_METADATA: &[u8]
Main contract metadata, see
ContractMetadataKind
for encoding details. Read moreSource§type Slot = VariableBytes<RECOMMENDED_STATE_CAPACITY>
type Slot = VariableBytes<RECOMMENDED_STATE_CAPACITY>
Slot type used by this contract
Source§impl TrivialType for State
impl TrivialType for State
Source§const METADATA: &[u8]
const METADATA: &[u8]
Data structure metadata in binary form, describing shape and types of the contents, see
IoTypeMetadataKind
for encoding details.const SIZE: u32 = _
Source§unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
Create a reference to a type, which is represented by provided memory. Read more
impl Copy for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IoType for Twhere
T: TrivialType,
impl<T> IoType for Twhere
T: TrivialType,
Source§const METADATA: &'static [u8] = T::METADATA
const METADATA: &'static [u8] = T::METADATA
Data structure metadata in binary form, describing shape and types of the contents, see
IoTypeMetadataKind
for encoding detailsSource§type PointerType = T
type PointerType = T
Pointer with trivial type that this
IoType
representsSource§unsafe fn size_ptr(&self) -> impl Deref<Target = NonNull<u32>>
unsafe fn size_ptr(&self) -> impl Deref<Target = NonNull<u32>>
Pointer to the number of bytes that are currently used to store data. Read more
Source§unsafe fn size_mut_ptr(&mut self) -> impl DerefMut
unsafe fn size_mut_ptr(&mut self) -> impl DerefMut
An exclusive pointer to the number of bytes that are currently used to store data. Read more
Source§unsafe fn capacity_ptr(&self) -> impl Deref<Target = NonNull<u32>>
unsafe fn capacity_ptr(&self) -> impl Deref<Target = NonNull<u32>>
Number of bytes are allocated right now Read more
Source§unsafe fn from_ptr<'a>(
ptr: &'a NonNull<<T as IoType>::PointerType>,
size: &'a u32,
capacity: u32,
) -> impl Deref<Target = T> + 'a
unsafe fn from_ptr<'a>( ptr: &'a NonNull<<T as IoType>::PointerType>, size: &'a u32, capacity: u32, ) -> impl Deref<Target = T> + 'a
Create a reference to a type, which is represented by provided memory. Read more
Source§unsafe fn from_mut_ptr<'a>(
ptr: &'a mut NonNull<<T as IoType>::PointerType>,
_size: &'a mut *mut u32,
capacity: u32,
) -> impl DerefMut + 'a
unsafe fn from_mut_ptr<'a>( ptr: &'a mut NonNull<<T as IoType>::PointerType>, _size: &'a mut *mut u32, capacity: u32, ) -> impl DerefMut + 'a
Create a mutable reference to a type, which is represented by provided memory. Read more
Source§unsafe fn as_ptr(
&self,
) -> impl Deref<Target = NonNull<<T as IoType>::PointerType>>
unsafe fn as_ptr( &self, ) -> impl Deref<Target = NonNull<<T as IoType>::PointerType>>
Get a raw pointer to the underlying data with no checks. Read more
Source§unsafe fn as_mut_ptr(&mut self) -> impl DerefMut
unsafe fn as_mut_ptr(&mut self) -> impl DerefMut
Get an exclusive raw pointer to the underlying data with no checks. Read more