Interact with value returned by parse even with question mark

Pretty basic stuff but any solution that I find either looks very scrappy and ugly or looks like poor programming.

image

Hope you can understand this image.
Is there any way I can multiply that value for 60 even with the question mark there? Thank you all!!!

The question mark means "if the Result is an Err, return it; otherwise unwrap the Ok value." It is very commonly used in Rust so you could just try to get used to it.

But if that behavior is not what you want, or you can't tolerate the syntax, you can:

  • do a match on the result with an arm for the Ok and another arm for the Err, or
  • use one of the Result methods to handle the Err and Ok cases, or
  • use an if let or let ... else to match on the Ok case and return or panic in the else (the Err case).
1 Like

I am not sure if the previous response is an accurate interpretation of the question. And now I’m beginning to question my own interpretation. But you can just do the multiply in the most natural way and it will work: Rust Playground

If you have any other context to clarify what you are asking, maybe someone will come up with a better solution.

2 Likes

Yes, I know the usage of the question mark, just struggling with the syntax?

Your solutions are nice and I'll probably use one of then according to my program, but what I'm looking for is:

A code of one line where if the Result is and Err, the ? will return it. Otherwise, if it's ok, the ? will unwrap it, and then multiply it by 60, all in the same line. Is it possible?

Hey, that's that! You interpreted it correctly, check my other last response.

I didn't think it would compile and work just by adding the * 60 at the ending, I even had tried that but it didn't work, I might have added a semicolon unintentionally...

tysm

1 Like