Description
https://github.com/starkware-libs/starknet-api/blob/main/src/core.rs#L48-L50
The Deref traits have been derived over many of the wrapper types built on top of the StarkFetl
type.
I guess that it was done to reduce the boilerplate induced by this design, which resulted in some "URL-like" syntax, eg: "contract_address.0.0".
This a a major design issue. Deref
should be used for smart pointers and similar types. It is a feature of the language which is built around the concept of References
, it should not be used for regular types casting. Into/From
is the language intended way to do this type of operation. Those are the traits you should be implementing on those many wrapper types.
The Deref
trait is a powerful tool, that is used in many places and should be implemented with care and only for smart pointers. You will find may resources online explaining why this specific usage is wrong, but you can start with this StackOverflow question. The Deref doc is also a good source of knowledge on this question, but a bit less explicit.
What should be done?
Those derive
implementations should be removed as soon as possible.
They can later on be replaced by some From/Into
implementations, that you can also get from the derive_more
crate.