Rust has a built-in generic type called Option<T>
, so a value of type
Option<i32>
can be read as "I either have a valid 32-bit integer, or
nothing." Using it as a return type tells your callers that you might fail,
and makes sure that they handle that possibility correctly.
pub fn maybe_divide(x: i32, y: i32) -> Option<i32>
would be the signature of a function which might fail to produce a value