You need to remove the ";" at the end of the match block. That's what causes that unit type (i.e. nothing) to be returned.
I can spot one other error, but I imagine you will be able to figure that out yourself.
You need to remove the ";" at the end of the match block. That's what causes that unit type (i.e. nothing) to be returned.
I can spot one other error, but I imagine you will be able to figure that out yourself.
Thanks! Now I don't understand the purpose of the semi-colon at the end of the match block in the examples lol.
I guess the other error was to add qty * cost_per_item + processing_fee
inside an Ok()
. (Or maybe to add ::<i32>
after the parse function that I somehow deleted)
If the last statement in a function has no semicolon at the end, it will automatically be returned from the function (just like using the return function). If it has a semicolon, nothing will be returned (which is the unit type ()
in your error message).
Oh, I get it! So it's that simple lol. I feel stupid :).
Never feel stupid about such things. This is how learning works. And, in my opinion, it is one of the most amazing processes of a human mind. Have fun with Rust.
Thanks. ^^
Yeah, needing to wrap that in an Ok()
is what I had spotted. :)
You also don't need that match there. You should be able to do :
let qty = item_quantity.parse()?;
let whatever = qty * cost_per_item + processing_fee;
Ok(whatever)
Check out the sections on error handling in the rust book.
That's what I did at first but I wanted to understand how to use match since they stated that we could use both case.