3 ms·
If function in Rust returns any type of result except Result, you can just call it without handling errors. Compiler will raise warning only if Result wasn't ha
by EugeneOZ 10y ago
If function in Rust returns any type of result except Result, you can just call it without handling errors. Compiler will raise warning only if Result wasn't handled. And even in this case you can just add "let _ =" before call to suppress warning. I'm pretty sure you know it.
- deleted 10y ago[deleted]
- masklinn 10y ago> If function in Rust returns any type of result except Result The conversation was specifically about ignoring errors. In Rust, errors are conventionally reported using Result hence it warning on unuse — AFAIK the only type opted into that by default, its variants being specifically called Ok and Err, and its currently exclusive support in `try!` and `?` > And even in this case you can just add "let _ =" before call to suppress warning. You can even disable the warning entirely, can you imagine that? Incidentally, you can use that exact same feature to ignore errors from value-returning functions (where you need the actual result) in Go as well, so that's not exactly a slam dunk; and it is an explicit ignoring of the error rather than an implicit one which can (and often is) a mistake rather than a conscious decision by the developer. That is, there is a large difference between _ := os.Chmod(…) where the developer is explicitly stating "I don't care about an error" and os.Chmod(…) where the developer might not have noticed that an error is possible. In Rust, the latter is will warn by default because fs::set_permissions returns an io::Result<()>.
- EugeneOZ 10y agoThere's a plenty of ways how function can report about error - with None, 0, -1, false, or even "error", can you imagine it? I like Rust's way to handle errors with Result, but I hate your tone, so discussion is over.
- mkawia 10y agoThink as an author of a function that does something that can fail . the signature ;"fn risky_shtuff() -> Result<Response , Err)" Rust guarantees to you as the author who ever uses this function HAS to handle both cases (even if it's an unwrap). However Rust doesn't stop you form making functions that instead return Option ,bools or even strings ,but you'd be actively working against very strong convention.
- EugeneOZ 10y agoif function doesn't return anything (void) as pcwalton saying, it doesn't matter. So or we are talking about returning value or not.