4 ms·
match number_str.parse::<i32>() { This matches on the return value of parse, which is an Result<T>. It can have two values: Err(E), or Ok(T). Ok(n) =>
by steveklabnik 12y ago
match number_str.parse::<i32>() {
This matches on the return value of parse, which is an Result<T>. It can have two values: Err(E), or Ok(T).
Ok(n) => Ok(2 * n),
This line matches an Ok(T), and binds the value of type T to n, which can then be used on the right hand side.
Err(err) => Err(err),
this line matches an Err(T), and binds the value of type T to err, which can be used on the right hand side.
The right hand sides re-wrap these values into another Result.
- phaylon 12y agoNitpick: Result<T, E> instead of Result<T> assuming Result is std::result::Result.
- steveklabnik 12y agoAhh yes, thank you.
- msie 12y agoThanks!