Is there a less verbose way to specify the type of the err argument for the closure in map_err()?
In many other cases the type is inferred.
use std::convert::TryInto;
#[derive(Debug)]
struct MyError {
pub msg: String
}
fn main() -> std::result::Result<(), MyError> {
let some_usize: usize = 0;
let some_i32: i32 = some_usize
.try_into()
.map_err(|err: <i32 as std::convert::TryFrom<usize>>::Error| MyError{ msg: err.to_string()})?;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// remove this and it doesn't compile.
Ok(())
}
Of course, the code some_i32 = some_usize as i32 works, and surprisingly, using i32::try_from(some_usize).map_err(...) DOES infer the type of err. So, I do have alternatives, but I'm still curious if there's an answer to my question.