Language Suggestion for .expect

I would like to be able to produce more informative messages with .expect.
I.e. to print out some variables values as well as just a string.
Do you think it might be possible for .expect to have on the error reporting side the same functionality as
writeln!(&mut std::io::stderr(),String, arg1, arg2 ....) ?

Could you use expect(format!(...))?

The problem with expect(format!(...)) is that you'll do that formatting regardless of whether it will be used. Maybe this is better: unwrap_or_else(|| panic!("your message {} {}, arg1, arg2))

3 Likes

Yeah, that's true. Maybe an expect<F: FnOnce() -> String>(f: F) would be nice.

2 Likes