onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
531 stars 139 forks source link

Cadence should support Enums with string raw type #1528

Open RohaanAdvani68 opened 2 years ago

RohaanAdvani68 commented 2 years ago

Issue To Be Solved

Cadence should have in built support for Enums with String raw type, instead of only integer based raw type. This is a standard feature of Enums expected of high level languages. This enables developers to avoid having to explicitly write out custom functions to convert String representations of Enum values to Enum object and vice versa within the smart contract. This will also simplify logic for developers on the frontend who will no longer have to map Enum raw int values to the string representation.

Suggested Solution

Developers should be able to simply use String type for enums when defining them in the smart contract. This should implicitly map Enum value to string representation unless explicitly defined. Cadence should expose basic functionality for mapping from enum value to string representation and vice versa.

Eg.

pub enum Rarity: String {
    Blue,
    Green
}

OR

pub enum Rarity: String {
    Blue("Blue color")
    Green("Green color")
}

Developers should be able to do something like rarity.toString() and Rarity(rarityStr) to convert easily between Enum values and string representation.

PratikDhanave commented 1 year ago

hi @turbolent @j1010001 @bjartek @RohaanAdvani68 is this issue is resolved ? if yes humble request please can we mark it as closed ?

turbolent commented 1 year ago

No, this feature has not been added yet