1. 11
    Rustlings functions4: Declaring the return type of a function
    43s

Rustlings functions4: Declaring the return type of a function

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

README for this exercise.

Chris Biscardi: [0:00] 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.

[0:27] 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.