Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abusive deref implementation! #197

Open
tdelabro opened this issue Mar 20, 2024 · 0 comments
Open

abusive deref implementation! #197

tdelabro opened this issue Mar 20, 2024 · 0 comments

Comments

@tdelabro
Copy link
Contributor

tdelabro commented Mar 20, 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 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.

@tdelabro tdelabro changed the title abusive deref implementation abusive deref implementation! Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant