Hi,
I don't understand why this
use std::fmt;
enum MyErrors {
MyError,
WriteError(fmt::Error)
}
impl From<fmt::Error> for MyErrors {
fn from(e: fmt::Error) -> Self {
MyErrors::WriteError(e)
}
}
fn test(s: &mut dyn fmt::Write) -> Result<(), MyErrors> {
write!(s, "test")
}
gives me the error
error[E0308]: mismatched types
--> src/main.rs:15:5
|
14 | fn test(s: &mut dyn fmt::Write) -> Result<(), MyErrors> {
| -------------------- expected `std::result::Result<(), MyErrors>` because of return type
15 | write!(s, "test")
| ^^^^^^^^^^^^^^^^^ expected enum `MyErrors`, found struct `std::fmt::Error`
|
= note: expected type `std::result::Result<_, MyErrors>`
found type `std::result::Result<_, std::fmt::Error>`
The example from the documentation for std::convert::From seems to do the exactly same thing and it compiles. Can anybody explain this, please.