fixes multi level inheritance (like 3 or more level of contract inheritance).
allows to remove #[borrow] attributes tottaly (currently borrow attributes left for compatibility reason).
lets to retrieve mutable and immutable references to a contract laying beneath struct that implements TopLevelStorage.
can fix #107 and help to #106
Low Level
TopLevelStorage got two additional functions to retrieve inner laying type of contract by generic param <S>.
A new trait StorageLevel exposes two similar functions that just returns optional reference to the type <S>.
StorageLevel implemented by every type that can exist in contract storage same as StorageType. Simple storage types implementation returns just None since we're not expecting them to store inherited contract.
Contracts implement StorageLevel within solidity_storage macro. Implementation checks that type of self is T if so reference will be returned (unsafe reference cast). Since every storage type implements StorageLevel trait then we can call same functions in every field recursively.
We can remove BorrowMut constraint from the router trait and use our newly created functions to retrieve references to inner contracts. This example with inheritance of three is working now.
#[borrow] attributes will generate Borrow and BorrowMut bindings still but basically there is no need in them.
Compatibility
generically typed contracts should have generics restricted by 'static lifetime. (example)
Checklist
[x] I have documented these changes where necessary.
[x] I have read the DCO and ensured that these changes comply.
Description
High Level
#[borrow]
attributes tottaly (currently borrow attributes left for compatibility reason).TopLevelStorage
.Low Level
TopLevelStorage
got two additional functions to retrieve inner laying type of contract by generic param<S>
.A new trait
StorageLevel
exposes two similar functions that just returns optional reference to the type<S>
.StorageLevel
implemented by every type that can exist in contract storage same asStorageType
. Simple storage types implementation returns justNone
since we're not expecting them to store inherited contract.Contracts implement
StorageLevel
withinsolidity_storage
macro. Implementation checks that type of self isT
if so reference will be returned (unsafe reference cast). Since every storage type implementsStorageLevel
trait then we can call same functions in every field recursively.We can remove
BorrowMut
constraint from the router trait and use our newly created functions to retrieve references to inner contracts. This example with inheritance of three is working now.#[borrow]
attributes will generateBorrow
andBorrowMut
bindings still but basically there is no need in them.Compatibility
'static
lifetime. (example)Checklist