Open nymoral opened 11 months ago
With the use of a private interface should be able to avoid this, sth like this
package main
import "fmt"
type FooBarKind uint
const (
FooKind FooBarKind = 0
BarKind FooBarKind = 1
ForgottenKind FooBarKind = 2
)
type Enum interface {
enum
}
func (v FooBarKind) value() uint {
return uint(v)
}
type enum interface {
value() uint
}
func printEnum(val Enum) {
fmt.Println("hello %v", val)
}
func main() {
printEnum(FooKind)
printEnum(3) // compile error cannot use 3 (constant of type int) as Enum value in argument to printEnum: int does not implement Enum (missing method value)
}
Using an invalid valid as an enum causes the rust bindings to panic:
causes Rust panic: