I cannot get the following code to compile.
- I get an error that
Fromis already implemented. - If I remove the manual impl of
FromI get the error thatFromis not implemented. - If I do not implement
Errorit works fine.
I suppose that this is due to the blank impl impl<T> From<T> for T in core. How should I work around this? Not implementing Error is not really an option.
Code (playground)
use std::fmt;
use std::io;
use std::error::Error;
#[derive(Debug)]
enum ErrorType {
Other(Box<Error>)
}
impl fmt::Display for ErrorType {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str("not implemented")
}
}
impl Error for ErrorType {
fn description(&self) -> &str {
use self::ErrorType::*;
match *self {
Other(ref err) => err.description(),
}
}
}
impl<E: Error + 'static> From<E> for ErrorType {
fn from(other: E) -> Self {
ErrorType::Other(Box::new(other))
}
}
fn ret_io_err() -> Result<(), io::Error> {
Ok(())
}
fn ret_error_type() -> Result<(), ErrorType> {
try!(ret_io_err());
Ok(())
}
fn main() {}