I'm curious about this situation:
fn main() {
foo()
}
fn foo() -> () {
let hello_world = "Hello, world!";
let res = println!("{}", hello_world);
res
}
While this isn't likely to fail, I imagine there are cases where it could. Arguably, anything involving I/O could fail. It seems like requiring the signature to be fn foo() -> Result<(), Error>
would be appropriate here. I'm not aware of any major usability issues with this, as you could always explicitly panic if needed. This also makes it more clear that yes, foo
is doing something that might fail. If we wanted to be clear it was I/O related we could introduce a type alias to Result<(), Error>
for clarity, but I already think making the more fundamental change would be enough for most.
I'm sure there are other instances like this, not just println!
, but it is the one I've seen the most.