My Site Blog

Enumerations and Match statement

Rust makes use of Enumerations and the standard 'match' statement to force user to handle every possible value of an Enum. 'Result' and 'Option' are 2 such examples, that are heavily used in Rust Standard Library.

'Result' enum

'Result' is used when a function might throw an error. It has Ok() and Err() values in it. Each signifying the Success or Failure outcome.

Result<T, Error>

'Option' enum

This is used on situations where a variable can hold a null value.

Option(T)