bynk.types.question_on_non_result
Error ? was applied to a non-Result value.
? unwraps an Ok and returns early from the function on an Err, so it needs a Result[T, E]: a plain Int has no error to return. The one other operand it takes is an Option, in an HttpResult handler. Apply ? to the call that produces the Result, not to a value already unwrapped. To turn an Option into a Result elsewhere, use .okOr(err).
Example
fn checked(n: Int) -> Result[Int, String] { if n >= 0 { Ok(n) } else { Err("negative") }}
fn run(n: Int) -> Result[Int, String] { let v = n? // ✗ `n` is an `Int`, not a `Result` Ok(v + 1)}
fn run(n: Int) -> Result[Int, String] { let v = checked(n)? // ✓ Ok(v + 1)}In the Book
See also
- The grammar rule it governs:
question_expr. - Every code in its category, Type checking, on the diagnostic index.
bynk explain bynk.types.question_on_non_resultshows the same from the installed toolchain, without a network.