Skip to content

Struct based enums #310

@kirillkuzin

Description

@kirillkuzin

Hey, I haven't found any way to generate struct based enums that can be used to avoid assigning incorrect values to variables of enum type. I guess this could be a useful improvement, what do you think?
The example of enum I'm talking about:

type Role struct {
	slug string
}

func (r Role) String() string {
	return r.slug
}

var (
	Unknown   = Role{""}
	Guest     = Role{"guest"}
	Member    = Role{"member"}
	Moderator = Role{"moderator"}
	Admin     = Role{"admin"}
)

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