Module option
Expand
Representing (Valid, Data)-pairs
The Option type represents values which are not always present. In hardware terms
it is used to represent a (valid, data)-pair. The compiler ensures that the invalid
case is dealt with when an option type is used, preventing accidental reading of
invalid values.
Valid values are written as Some(value) while invalid values are written None.
The primary way to interact with Option types is via match statements. For example,
To transform the underlying data by adding one, you can write:
match option {
Some(value) => Some(value + 1),
None => None
}Enums
- Option
Represents a (valid, data) pair.