Hacker News new | ask | show | jobs
by a_cul 3 hours ago
You're missing how rust works. The function is explicitly allowed to fail, which is why it returns a Result<(), Error>. They're using the function calls within for their side effects. The ? at the end of each line signals that the function will short-circuit return with an error if the function call fails, and only if it is successful it returns the actual value: they just don't care about this value, hence the let _ =. Basically, they are doing the equivalent of:

  let _, err = function_call();
  if err {
    return err
  }
  ...
1 comments

What I am saying, is make another version of the function, which is explicitly not allowed to fail, if you want to use it in the loop.
What would that function do? Fully copy/paste the original impl and ignore the errors in the body? Call the original function and ignore the error? In each of those scenarios you’d still need syntax for “call function and ignore error”, so you’re right back where you started.

Unless you’re proposing writing alternative “error-ignoring” versions of everything in the std::io namespace, your idea doesn’t even make sense.