Allow deriving storage traits for foreign types #1863
Labels
A-ink_lang
[ink_lang] Work item
A-ink_storage
[ink_storage] Work Item
C-discussion
An issue for discussion for a given topic.
In to place a type into contract storage we require it implement certain storage specific traits. Those are meant to be derived
and not implemented. This is a problem if a contract wants to store foreign types as it cannot use the derive macros on them.
After looking through or examples the affected traits seem to be:
The scale and scale info types are a bit more common but still parity specific and meant to be derived.
Please note that we don't know how common this case is and if we are willing to put in the work to support this for what might be a niche feature. Needs a discussion.
Suggested Solution
Presently, when deriving a type we require all contained types of a struct (or enum) to implement the type we are deriving in order to forward to them. In our case where the type is foreign we can't derive. The workaround is to newtype and manually add a forwarding impl. This is clearly not a good solution especially if the foreign type contains further foreign types. The boilerplate adds up.
To automate this we need to write a derive macro that derives the trait it is deriving on struct A for all types contained in A that don't already implement that trait. A recursive derive so to say:
The text was updated successfully, but these errors were encountered: