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§
Trait Implementations§
source§impl<T: ContractRef> Deref for External<T>
impl<T: ContractRef> Deref for External<T>
source§impl<T: ContractRef> DerefMut for External<T>
impl<T: ContractRef> DerefMut for External<T>
source§impl<T: ContractRef> ModuleComponent for External<T>
impl<T: ContractRef> ModuleComponent for External<T>
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> 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