goki.dev/laser@v0.1.34/testdata/enumgen.go (about) 1 // Code generated by "enumgen"; DO NOT EDIT. 2 3 package testdata 4 5 import ( 6 "errors" 7 "strconv" 8 "strings" 9 10 "goki.dev/enums" 11 ) 12 13 var _FruitsValues = []Fruits{0, 1, 2, 3, 4, 5, 6} 14 15 // FruitsN is the highest valid value 16 // for type Fruits, plus one. 17 const FruitsN Fruits = 7 18 19 // An "invalid array index" compiler error signifies that the constant values have changed. 20 // Re-run the enumgen command to generate them again. 21 func _FruitsNoOp() { 22 var x [1]struct{} 23 _ = x[Apple-(0)] 24 _ = x[Orange-(1)] 25 _ = x[Peach-(2)] 26 _ = x[Strawberry-(3)] 27 _ = x[Blackberry-(4)] 28 _ = x[Blueberry-(5)] 29 _ = x[Apricot-(6)] 30 } 31 32 var _FruitsNameToValueMap = map[string]Fruits{ 33 `Apple`: 0, 34 `apple`: 0, 35 `Orange`: 1, 36 `orange`: 1, 37 `Peach`: 2, 38 `peach`: 2, 39 `Strawberry`: 3, 40 `strawberry`: 3, 41 `Blackberry`: 4, 42 `blackberry`: 4, 43 `Blueberry`: 5, 44 `blueberry`: 5, 45 `Apricot`: 6, 46 `apricot`: 6, 47 } 48 49 var _FruitsDescMap = map[Fruits]string{ 50 0: ``, 51 1: ``, 52 2: ``, 53 3: ``, 54 4: ``, 55 5: ``, 56 6: ``, 57 } 58 59 var _FruitsMap = map[Fruits]string{ 60 0: `Apple`, 61 1: `Orange`, 62 2: `Peach`, 63 3: `Strawberry`, 64 4: `Blackberry`, 65 5: `Blueberry`, 66 6: `Apricot`, 67 } 68 69 // String returns the string representation 70 // of this Fruits value. 71 func (i Fruits) String() string { 72 if str, ok := _FruitsMap[i]; ok { 73 return str 74 } 75 return strconv.FormatInt(int64(i), 10) 76 } 77 78 // SetString sets the Fruits value from its 79 // string representation, and returns an 80 // error if the string is invalid. 81 func (i *Fruits) SetString(s string) error { 82 if val, ok := _FruitsNameToValueMap[s]; ok { 83 *i = val 84 return nil 85 } 86 if val, ok := _FruitsNameToValueMap[strings.ToLower(s)]; ok { 87 *i = val 88 return nil 89 } 90 return errors.New(s + " is not a valid value for type Fruits") 91 } 92 93 // Int64 returns the Fruits value as an int64. 94 func (i Fruits) Int64() int64 { 95 return int64(i) 96 } 97 98 // SetInt64 sets the Fruits value from an int64. 99 func (i *Fruits) SetInt64(in int64) { 100 *i = Fruits(in) 101 } 102 103 // Desc returns the description of the Fruits value. 104 func (i Fruits) Desc() string { 105 if str, ok := _FruitsDescMap[i]; ok { 106 return str 107 } 108 return i.String() 109 } 110 111 // FruitsValues returns all possible values 112 // for the type Fruits. 113 func FruitsValues() []Fruits { 114 return _FruitsValues 115 } 116 117 // Values returns all possible values 118 // for the type Fruits. 119 func (i Fruits) Values() []enums.Enum { 120 res := make([]enums.Enum, len(_FruitsValues)) 121 for i, d := range _FruitsValues { 122 res[i] = d 123 } 124 return res 125 } 126 127 // IsValid returns whether the value is a 128 // valid option for type Fruits. 129 func (i Fruits) IsValid() bool { 130 _, ok := _FruitsMap[i] 131 return ok 132 } 133 134 // MarshalText implements the [encoding.TextMarshaler] interface. 135 func (i Fruits) MarshalText() ([]byte, error) { 136 return []byte(i.String()), nil 137 } 138 139 // UnmarshalText implements the [encoding.TextUnmarshaler] interface. 140 func (i *Fruits) UnmarshalText(text []byte) error { 141 return i.SetString(string(text)) 142 } 143 144 var _FoodsValues = []Foods{7, 8, 9, 10} 145 146 // FoodsN is the highest valid value 147 // for type Foods, plus one. 148 const FoodsN Foods = 11 149 150 // An "invalid array index" compiler error signifies that the constant values have changed. 151 // Re-run the enumgen command to generate them again. 152 func _FoodsNoOp() { 153 var x [1]struct{} 154 _ = x[Bread-(7)] 155 _ = x[Lettuce-(8)] 156 _ = x[Cheese-(9)] 157 _ = x[Meat-(10)] 158 } 159 160 var _FoodsNameToValueMap = map[string]Foods{ 161 `Bread`: 7, 162 `bread`: 7, 163 `Lettuce`: 8, 164 `lettuce`: 8, 165 `Cheese`: 9, 166 `cheese`: 9, 167 `Meat`: 10, 168 `meat`: 10, 169 } 170 171 var _FoodsDescMap = map[Foods]string{ 172 7: ``, 173 8: ``, 174 9: ``, 175 10: ``, 176 } 177 178 var _FoodsMap = map[Foods]string{ 179 7: `Bread`, 180 8: `Lettuce`, 181 9: `Cheese`, 182 10: `Meat`, 183 } 184 185 // String returns the string representation 186 // of this Foods value. 187 func (i Foods) String() string { 188 if str, ok := _FoodsMap[i]; ok { 189 return str 190 } 191 return Fruits(i).String() 192 } 193 194 // SetString sets the Foods value from its 195 // string representation, and returns an 196 // error if the string is invalid. 197 func (i *Foods) SetString(s string) error { 198 if val, ok := _FoodsNameToValueMap[s]; ok { 199 *i = val 200 return nil 201 } 202 if val, ok := _FoodsNameToValueMap[strings.ToLower(s)]; ok { 203 *i = val 204 return nil 205 } 206 return (*Fruits)(i).SetString(s) 207 } 208 209 // Int64 returns the Foods value as an int64. 210 func (i Foods) Int64() int64 { 211 return int64(i) 212 } 213 214 // SetInt64 sets the Foods value from an int64. 215 func (i *Foods) SetInt64(in int64) { 216 *i = Foods(in) 217 } 218 219 // Desc returns the description of the Foods value. 220 func (i Foods) Desc() string { 221 if str, ok := _FoodsDescMap[i]; ok { 222 return str 223 } 224 return Fruits(i).Desc() 225 } 226 227 // FoodsValues returns all possible values 228 // for the type Foods. 229 func FoodsValues() []Foods { 230 es := FruitsValues() 231 res := make([]Foods, len(es)) 232 for i, e := range es { 233 res[i] = Foods(e) 234 } 235 res = append(res, _FoodsValues...) 236 return res 237 } 238 239 // Values returns all possible values 240 // for the type Foods. 241 func (i Foods) Values() []enums.Enum { 242 es := FruitsValues() 243 les := len(es) 244 res := make([]enums.Enum, les+len(_FoodsValues)) 245 for i, d := range es { 246 res[i] = d 247 } 248 for i, d := range _FoodsValues { 249 res[i+les] = d 250 } 251 return res 252 } 253 254 // IsValid returns whether the value is a 255 // valid option for type Foods. 256 func (i Foods) IsValid() bool { 257 _, ok := _FoodsMap[i] 258 if !ok { 259 return Fruits(i).IsValid() 260 } 261 return ok 262 } 263 264 // MarshalText implements the [encoding.TextMarshaler] interface. 265 func (i Foods) MarshalText() ([]byte, error) { 266 return []byte(i.String()), nil 267 } 268 269 // UnmarshalText implements the [encoding.TextUnmarshaler] interface. 270 func (i *Foods) UnmarshalText(text []byte) error { 271 return i.SetString(string(text)) 272 }