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§
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
Source§impl<M> HasEvents for Mwhere
M: ModulePrimitive,
impl<M> HasEvents for Mwhere
M: ModulePrimitive,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
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>
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>
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>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
Fill
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut wrapper.