You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
tdelabro
changed the title
abusive deref implementation
abusive deref implementation!
Mar 22, 2024
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 ofReferences
, 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 thederive_more
crate.The text was updated successfully, but these errors were encountered: