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

C-COMMON-TRAITS favors implementing traits too eagerly #268

Open
Enet4 opened this issue Aug 29, 2022 · 0 comments
Open

C-COMMON-TRAITS favors implementing traits too eagerly #268

Enet4 opened this issue Aug 29, 2022 · 0 comments

Comments

@Enet4
Copy link

Enet4 commented Aug 29, 2022

C-COMMON-TRAITS says that "crates that define new types should eagerly implement all applicable, common traits." The problem with this comes with the vague definition of applicable, which may indicate that one should simply implement as many common traits as it can, such as Eq and Org. The drawbacks of this:

  • If a struct deriving Eq or Ord adds a private field which does not implement one of these, we have to drop that implementation, leading to a major breaking change in the API. It does not seem reasonable to fully impose this guideline and cause that certain future changes to public structs turn into API changes.
  • See also C-COMMON-TRAITS and enums #99: Deriving Ord might not have a meaningful implementation on enums, and it is unclear what benefits are attained from demanding these types to implement Ord and Default when there isn't a meaningful order between variants or a variant which could be considered the default one.

I suggest that the guideline is rephrased to drop the idea of "eagerly" implementing traits, and let developers understand that they should strike a balance between attaining interoperability with the ecosystem and writing a stable API that won't break due to a premature derive.

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