Trait ink_env::call::ConstructorReturnType
source · pub trait ConstructorReturnType<C> {
type Output;
type Error: Decode;
const IS_RESULT: bool = false;
// Required method
fn ok(value: C) -> Self::Output;
// Provided method
fn err(_err: Self::Error) -> Option<Self::Output> { ... }
}
Expand description
Represents any type that can be returned from an ink!
constructor. The following
contract implements the four different return type signatures implementing this trait:
Self
Result<Self, Error>
Contract
Result<Contract, Error>
#[ink::contract]
mod contract {
#[ink(storage)]
pub struct Contract {}
#[derive(Debug, PartialEq, Eq)]
#[ink::scale_derive(Encode, Decode, TypeInfo)]
pub enum Error {
Foo,
}
impl Contract {
#[ink(constructor)]
pub fn new_self() -> Self {
Self {}
}
#[ink(constructor)]
pub fn new_storage_name() -> Contract {
Contract {}
}
#[ink(constructor)]
pub fn new_result_self() -> Result<Self, Error> {
Ok(Self {})
}
#[ink(constructor)]
pub fn new_result_storage_name() -> Result<Contract, Error> {
Ok(Contract {})
}
#[ink(message)]
pub fn message(&self) {}
}
}
These constructor return signatures are then used by the ContractRef
codegen for the
CreateBuilder::returns
type parameter.
Required Associated Types§
Provided Associated Constants§
Required Methods§
Provided Methods§
Implementations on Foreign Types§
source§impl<C, E> ConstructorReturnType<C> for Result<C, E>where
C: ContractEnv + FromAccountId<<C as ContractEnv>::Env>,
E: Decode,
impl<C, E> ConstructorReturnType<C> for Result<C, E>where C: ContractEnv + FromAccountId<<C as ContractEnv>::Env>, E: Decode,
Blanket implementation for a Result<Self>
return type. Self
in the context
of a ContractRef
inherent becomes the ContractRef
s type.
Implementors§
source§impl<C> ConstructorReturnType<C> for Cwhere
C: ContractEnv + FromAccountId<<C as ContractEnv>::Env>,
impl<C> ConstructorReturnType<C> for Cwhere C: ContractEnv + FromAccountId<<C as ContractEnv>::Env>,
Blanket implementation for ContractRef
types, generated for cross-contract calls.
In the context of a ContractRef
inherent, Self
from a constructor return
type will become the type of the ContractRef
’s type.