pub trait ConstructorReturnType<C> {
    type Output;
    type Error: Decode;

    const IS_RESULT: bool = false;

    fn ok(value: C) -> Self::Output;

    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, scale::Encode, scale::Decode)]
    #[cfg_attr(feature = "std", derive(::scale_info::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§

The actual return type of the constructor.

  • If a constructor returns Self, then Output = Self
  • If a constructor returns a Result<Self, E>, then Output = Result<Self, E>

The error type of the constructor return type.

Provided Associated Constants§

Is true if Self is Result<C, E>.

Required Methods§

Construct a success value of the Output type.

Provided Methods§

Construct an error value of the Output type.

Result implementations should return Some(Err(err)), otherwise default to None.

Implementations on Foreign Types§

Blanket implementation for a Result<Self> return type. Self in the context of a ContractRef inherent becomes the ContractRefs type.

Implementors§

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.