External

Struct 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: 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>

Source§

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> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> RngCore for T
where T: DerefMut, <T as Deref>::Target: RngCore,

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dst: &mut [u8])

Fill dest with random data. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<R> TryRngCore for R
where R: RngCore + ?Sized,

Source§

type Error = Infallible

The type returned in the event of a RNG error.
Source§

fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>

Return the next random u64.
Source§

fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>

Fill dest entirely with random data.
Source§

fn unwrap_err(self) -> UnwrapErr<Self>
where Self: Sized,

Wrap RNG with the UnwrapErr wrapper.
Source§

fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>

Wrap RNG with the UnwrapMut wrapper.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> CryptoRng for T
where T: DerefMut, <T as Deref>::Target: CryptoRng,

Source§

impl<R> TryCryptoRng for R
where R: CryptoRng + ?Sized,