#What is wrong with my code here
15 messages · Page 1 of 1 (latest)
you could also do return 0;
alright
do you know why this doesnt work?
does rust just not have that type of inference?
what it's seeing is you want to return 0 from the if block, not the function
then fall through and return that last statement you have
Only the last expression is implicit returned. if counts as one expression with its else if it has one, but your code as written has two expressions
self.sign.as_i8() is implicitly returned, and the if is not
By using an else, you can merge them into one expression. Alternatively, you can explicitly return the 0
got it thanks
Unrelated question
I'm trying to match the return value of signum() which returns 1, 0 or -1 but match is exhaustive so it complains if I match only those arms. What I've done instead is this:
match num.signum() * denom.signum() {
1 => sign = Sign::Positive,
-1 => sign = Sign::Negative,
0 => sign = Sign::Positive,
_ => sign = Sign::Positive // Eww
}```
Which I doesn't seem like great code
how can I go about this in a better way