Skip to content

Add support for variant attributes #22

Description

@philipp-haker

I usually like to combine Kinded with other traits. Examples are:

  • From<TraitEnumKind> for TraitEnum and Default for TraitEnumKind which is nice for enums containing implementors of a specific trait: let variant : TraitEnum = TraitEnumKind::default().into();
  • another is EnumMessage from strum to display additional information about the kinds.

While the Default impl is easy to do in the first case, manually implementing EnumMessage is a tad more annoying.
As a solution I would like to propose that variant attributes can also be passed on like so:

#[kinded(derive(Default, EnumMessage))]
pub enum UserId {
  #[kinded(default)]
  #[kinded(strum(message = "User by ID", detailed_message = "Identify a user by their (unique) id"))]
  ById(u64),

  #[kinded(strum(message = "User by Username", detailed_message = "Identify a user by their username"))]
  ByName(String),

  #[kinded(strum(message = "User by email", detailed_message = "Identify a user by their email address"))]
  ByEmail(String),
}

This would also solve #18 like this:

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename="camelCase")]
#[kinded(serde(rename="camelCase"))]
pub enum Event {
  #[serde(rename="LoggedIn"))]
  #[kinded(serde(rename="LoggedIn"))]
  Login(LoginDetail)
  Logout(LogoutDetail)
}

which does contain redundancies but is still better than the current way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions