Variant types are used for values whose type could be one of several compliant concrete types. Use of a variant-typed value requires pattern-matching or virtual dispatch.
There are several kinds of variant types:
- Option. A value that might be some type or could be null.
- Result. A value that might be one type for success and a different type for an error.
- Enums. A simple, fixed-sized value that could be one of several enumerated types.
- Traits, abstract types that can serve as a shared foundation for defining variant types.
- Virtual references. A dispatchable reference to some concrete type.