An enum is a fixed list of named values. Converting a number to an enum only makes sense for the numbers that correspond to a variant: the first variant is 0, the next 1, and so on.
Example
enum Color { Red, Green } // Red is 0, Green is 1mut c: Color = 1 to Color; // fine -- Greenmut d: Color = 7 to Color; // there is no variant number 7Turf checks a literal number at compile time and tells you the valid range (here 0 to 1), so a mistake like this never reaches your running program.
Usually the better fix is to skip the number entirely and use the variant by name:
Example
mut c: Color = Color::Green;If you are converting a number you computed or read in, check that it is in range first – a value that isn’t a variant has no sensible meaning.
Run turf --explain E127 in a terminal to read this again.