Hacker News new | past | comments | ask | show | jobs | submit login

From the left-hand side of the `=>` arrows in the `match` expression.



I know that. Where do they come from before that?


    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.


Nitpick: Result<T, E> instead of Result<T> assuming Result is std::result::Result.


Ahh yes, thank you.


Thanks!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: