Skip to content

Static check enum as type annotation #15

Open

Description

@Folyd
enum Color {
    Red = "#FF0000",
    Green = "#00FF00",
    Blue = "#0000FF",
}

fn get_color(color: Color) -> str {
    match color {
        Color::Red => "red",
        Color::Green => "green",
        Color::Blue => "blue",
    }
}

get_color(Color::Red); // red

enum AnotherEnum {}

get_color(AnotherEnum); // Error: AnotherEnum is not a Color

Activity

  1. added
    web
    on Mar 6, 2025
  2. added
    lang
    and removed
    web
    on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions