Generic Enums
Generic enum constructors can carry typed data. Type parameters are declared in angle brackets after the enum name, and can then be used in constructor parameter types. This allows enums to carry data of different types in different cases.
Result<T, E> uses Ok(T) to represent success with a value, and Err(E) to represent failure with error information. The two type parameters correspond to the success value type and error value type respectively, giving callers the freedom to choose. Option<T> is also a classic example of generic enum: Some(T) or None.
When pattern matching on generic enums, you can extract the carried values while retaining complete type information. Variables in match branches are inferred to be the corresponding types without manual conversion. This design makes error handling both type-safe and expressive.
Run the code to observe how Result is used, then add a Pending constructor without data and handle it in pattern matching.