Created
November 6, 2022 14:57
-
-
Save bozdoz/df442b61cf1224be59ae4f03ecaff662 to your computer and use it in GitHub Desktop.
exclusive_enums.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type dessert int | |
const ( | |
ICE_CREAM dessert = iota | |
CUP_CAKES | |
GUMMY_WORMS | |
) | |
type exclusive_dessert interface { | |
ignore_me() | |
} | |
func (d dessert) ignore_me() {} | |
// now use exclusive_dessert | |
func use_dessert(d exclusive_dessert) {} | |
// use_dessert(0) doesn't work! | |
// must use use_dessert(ICE_CREAM) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps implementing fmt.Sringer interface helps with formatting for better logs. Explored it a little bit on playground. It still has some limitations, specially inside structs.