When developing Ink! smart contracts I found that SpreadLayout
and SpreadAllocate
cannot be derived for simple structs or enums that are members variables of the contract and I have to implement the traits manually.
The compilation error occurs only when building the contract ( cargo +nightly contract build
) but not when running test (cargo +nightly test
)
for instance for the simple struct:
#[cfg_attr(feature = "std", derive(Debug, scale_info::TypeInfo, StorageLayout, SpreadAllocate))]
pub struct Data {
pub a: u64,
pub b: u64,
}
fails with:
error[E0277]: the trait bound `Data: SpreadAllocate` is not satisfied
--> /../lib.rs:23:14
|
23 | #[derive(SpreadAllocate)]
| ^^^^^^^^^^^^^^ the trait `SpreadAllocate` is not implemented for `Data`
|
= help: the following other types implement trait `SpreadAllocate`:
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
(A, B, C, D, E, F, G)
(A, B, C, D, E, F, G, H)
and 47 others
= note: this error originates in the derive macro `SpreadAllocate` (in Nightly builds, run with -Z macro-backtrace for more info)
adding SpreadLayout
and SpreadAllocate
to the derive macro fails.
Same for the enum
#[cfg_attr(feature = "std", derive(Debug, Clone, Copy, Encode, Decode, scale_info::TypeInfo, StorageLayout, SpreadLayout))]
pub enum Type {
Unknown,
A,
B,
}
what am I missing?