pub trait DispatchableConstructorInfo<const ID: u32> {
type Input;
type Storage;
type Output;
type Error;
const IS_RESULT: bool;
const CALLABLE: fn(Self::Input) -> Self::Output;
const DECODE: fn(&mut &[u8]) -> Result<Self::Input, DispatchError>;
const RETURN: fn(ReturnFlags, Result<(), &Self::Error>);
const PAYABLE: bool;
const SELECTOR: Option<[u8; 4]>;
const LABEL: &'static str;
const ABI: Abi;
}
Expand description
Stores various information of the respective dispatchable ink! constructor.
§Note
This trait is implemented by ink! for every dispatchable ink! constructor
of the root ink! smart contract. The ID
used in the trait reflects the
chosen or derived selector of the dispatchable ink! constructor.
§Usage
#[ink::contract]
pub mod contract {
#[ink(storage)]
pub struct Contract {}
impl Contract {
#[ink(constructor)]
pub fn constructor1() -> Self {
Contract {}
}
#[ink(constructor, selector = 0xC0DECAFE)]
pub fn constructor2(input1: i32, input2: i64) -> Self {
Contract {}
}
#[ink(message)]
pub fn message(&self) {}
}
}
use contract::Contract;
/// Asserts that the constructor with the selector `ID` has the following properties.
///
/// # Note
///
/// The `In` and `Out` generic parameters describe the input and output types.
fn assert_constructor_info<In, const ID: u32>(selector: [u8; 4], label: &str)
where
Contract: DispatchableConstructorInfo<{ ID }, Input = In>,
{
assert_eq!(
<Contract as DispatchableConstructorInfo<{ ID }>>::SELECTOR,
Some(selector),
);
assert_eq!(
<Contract as DispatchableConstructorInfo<{ ID }>>::LABEL,
label,
);
}
fn main() {
assert_constructor_info::<(), { selector_id!("constructor1") }>(
selector_bytes!("constructor1"),
"constructor1",
);
assert_constructor_info::<(i32, i64), 0xC0DECAFE_u32>(
[0xC0, 0xDE, 0xCA, 0xFE],
"constructor2",
);
}
Required Associated Constants§
Sourceconst CALLABLE: fn(Self::Input) -> Self::Output
const CALLABLE: fn(Self::Input) -> Self::Output
The closure that can be used to dispatch into the dispatchable ink! constructor.
Required Associated Types§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.