Course lesson
Rustlings functions4: Declaring the return type of a function
README for this exercise.
- Duration
- 1 min
- Access
- Free
- Transcript
- Available
README for this exercise.
Course lesson
README for this exercise.
README for this exercise.
Chris Biscardi: In functions4, let's reverse what we've been doing and take a look at the error message first, expected type, found '{'. At line 14, function sale_price, price is an i32. There's an arrow here where Rust expected a type. If we find line 14, we can see that sale_price takes a parameter that is an i32. It doesn't have a return value even though we've used the arrow here.
If we remember back to our if statement, we can see that we're implicitly returning price - 10 or price - 3. In that case, we can probably use an i32 since that's what the parameter is and we're operating with integers on it. Note our test is passed.
Course lesson
README for this exercise.