When a struct uses a generic KEY: StorageKey, the #[ink::storage_item] macro sets the ParentKey generic value to KEY, effectively concatenating them. This allows you to reuse the same type definition in different contexts with different storage keys.
Example usage in a contract:
#[ink(storage)]
struct MyContract {
my_struct: MyStruct<ManualKey<123>>,
}
Important: Avoid direct assignment of default instances.
Because every type is unique after code generation (due to its specific storage key), assigning a value like Balances::default() to a field that expects a specific ManualKey will cause a type mismatch error.
Incorrect:
instance.balances = Balances::<ManualKey<123>>::default(); // Error
Correct:
Use Default::default() to allow the compiler to generate the correct type with the expected storage key:
instance.balances = Default::default();
#[ink(storage)]
struct MyContract {
my_struct: MyStruct<ManualKey<123>>,
}
// Inside a constructor or method:
instance.balances = Default::default();