Skip to content

#[deriving(PartialEq, Eq, Show, Clone, Hash, PartialOrd, Ord, Default, Encodable, Decodable)] is too verbose #441

@comex

Description

@comex

If I have a small struct wrapping some basic types, or a basic enum, it's quite likely that the entire list of traits above is appropriate to derive (with the possible exception of Default). However, this is so noisy that, in practice, nobody seems to do so, including in the main Rust repository: for example, grep libsyntax for pub enum and look at how many of them cannot be used as keys in maps or even Shown. Instead, some random subset of traits is derived depending on what people actually need to do with the struct. But this is annoying:

  • If I need to add a new trait, it's usually a completely meaningless busywork change.
  • If the type is a public item from someone else's library, then I can't add a deriving, but would have to make a copy of the type and manually convert values back and forth in order to do whatever the trait is for. I haven't actually encountered this yet, but then again I haven't written that much code..

The most obvious solution would be a shortcut to derive as many traits as possible, though I'm not sure how that would interact with new derivable traits potentially being added in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions