Struct odra_core::External

source ·
pub struct External<T: ContractRef> { /* private fields */ }
Expand description

A module component that is a reference to an external contract.

§Example

use core::ops::DerefMut;
use odra::{Address, External, prelude::*};

#[odra::module]
pub struct Contract {
    ext: odra::External<SetterGetterContractRef>
}

#[odra::module]
impl Contract {
    pub fn init(&mut self, address: odra::Address) {
        self.ext.set(address);
    }

    /// If a contract implements the set() method, you can't use
    /// the deref coercion mechanism, so you call the `External::set()` method.
    /// In this case you need to dereference the contract explicitly:
    pub fn set(&mut self, value: bool) {
        self.ext.deref_mut().set(value);
        // or
        // DerefMut::deref_mut(&mut self.ext).set(value);
    }

    /// For any other method, you can use the deref coercion mechanism, and call
    /// the method directly on the external instance:
    pub fn get(&self) -> bool {
        self.ext.get()
    }
}

#[odra::external_contract]
pub trait SetterGetter {
    fn set(&mut self, value: bool);
    fn get(&self) -> bool;
}

Implementations§

source§

impl<T: ContractRef> External<T>

source

pub fn set(&mut self, address: Address)

Sets the address of the external contract.

Trait Implementations§

source§

impl<T: ContractRef> Deref for External<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: ContractRef> DerefMut for External<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T: ContractRef> ModuleComponent for External<T>

source§

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

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

source§

impl<T: ContractRef> ModulePrimitive for External<T>

Auto Trait Implementations§

§

impl<T> !Freeze for External<T>

§

impl<T> !RefUnwindSafe for External<T>

§

impl<T> !Send for External<T>

§

impl<T> !Sync for External<T>

§

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

§

impl<T> !UnwindSafe for External<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.