Struct odra::Var

source ·
pub struct Var<T> { /* private fields */ }
Expand description

Data structure for storing a single value.

Implementations§

source§

impl<T> Var<T>

source

pub fn env(&self) -> ContractEnv

Returns the contract environment associated with the variable.

source§

impl<T> Var<T>
where T: FromBytes,

source

pub fn get(&self) -> Option<T>

Retrieves the value of the variable.

Returns Some(value) if the variable has a value, or None if it is unset.

source

pub fn get_or_revert_with<E>(&self, error: E) -> T
where E: Into<OdraError>,

Retrieves the value of the variable or reverts with an error.

If the variable has a value, it is returned. Otherwise, the provided error is reverted.

source§

impl<T> Var<T>
where T: FromBytes + Default,

source

pub fn get_or_default(&self) -> T

Returns the value of the variable, or the default value of the type if the variable is None.

source§

impl<T> Var<T>
where T: ToBytes + CLTyped,

source

pub fn set(&mut self, value: T)

Sets the value of the variable.

source§

impl<V> Var<V>

source

pub fn add(&mut self, value: V)

Utility function that gets the current value and adds the passed value and sets the new value to the storage.

If the operation fails due to overflow, the currently executing contract reverts.

source§

impl<V> Var<V>

source

pub fn subtract(&mut self, value: V)

Utility function that gets the current value and subtracts the passed value and sets the new value to the storage.

If the operation fails due to overflow, the currently executing contract reverts.

Trait Implementations§

source§

impl<T> ModuleComponent for Var<T>

Implements the ModuleComponent trait for the Var struct.

source§

fn instance(env: Rc<ContractEnv>, index: u8) -> Var<T>

Creates a new instance of Var with the given environment and index.

source§

impl<M> SchemaErrors for Var<M>
where M: SchemaErrors,

source§

fn schema_errors() -> Vec<UserError>

Returns a vector of UserErrors.
source§

impl<M> SchemaEvents for Var<M>
where M: SchemaEvents,

source§

fn schema_events() -> Vec<Event>

Returns a vector of Events.
source§

fn custom_types() -> Vec<Option<CustomType>>

Returns a vector of CustomTypes. Read more
source§

impl<T> ModulePrimitive for Var<T>

Auto Trait Implementations§

§

impl<T> Freeze for Var<T>

§

impl<T> !RefUnwindSafe for Var<T>

§

impl<T> !Send for Var<T>

§

impl<T> !Sync for Var<T>

§

impl<T> Unpin for Var<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Var<T>

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.

source§

impl<M> HasEvents for M
where M: ModulePrimitive,

source§

fn events() -> Vec<Event>

Returns a list of Events used by the contract.
source§

fn event_schemas() -> BTreeMap<String, Schema>

Returns a map of event schemas used by the contract.
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.