Say I have the following:
use std::fs::File; impl From<i32> for Blah { fn from(b:i32) -> Blah { Blah {} } } fn main() {} enum MyError { ParseError, } impl From<std::io::Error> for MyError { fn from(_:std::io::Error) -> Self { MyError::ParseError } } fn get_result() -> Result<Blah, MyError> { let mut file = File::create("foo.txt")?; } This compiles fine. I don't understand how.
File::create throws an std::io::error, which we're trying to wrap in a MyError. But we never explicitly call from anywhere!? How does it compile?
As the comments from this answer Rust understanding From trait indicate, you do have to explicitly call from.
So, how is the above snippet compiling?