Derive Macro SolEncode
#[derive(SolEncode)]
Expand description
Derives an implementation of ink::SolEncode
for the given struct
or enum
.
§Note
All field types (if any) must implement [ink::SolEncode
].
§Example
use ink_macro::SolEncode;
#[derive(SolEncode)]
struct UnitStruct;
#[derive(SolEncode)]
struct TupleStruct(bool, u8, String);
#[derive(SolEncode)]
struct FieldStruct {
status: bool,
count: u8,
reason: String,
}
#[derive(SolEncode)]
enum SimpleEnum {
One,
Two,
Three,
}
#[derive(SolEncode)]
struct NestedStruct {
unit: UnitStruct,
tuple: TupleStruct,
fields: FieldStruct,
enumerate: SimpleEnum,
}
#[derive(SolEncode)]
struct GenericStruct<T> {
concrete: u8,
generic: T,
}
§Note
Solidity has no semantic equivalent for enums with fields (i.e. Solidity enums can only express the equivalent of Rust unit-only or field-less enums). So mapping complex Rust enums (i.e. enums with fields) to “equivalent” Solidity representations typically yields complex structures based on tuples (at Solidity ABI encoding level) and structs (at Solidity language level).
Because of this, this Derive
macro doesn’t generate [ink::SolEncode
]
implementations for enums with fields.