Closed
Description
#[derive(Debug)]
enum MainError {
IO(std::io::Error),
Parse(std::num::ParseIntError),
}
impl From<std::io::Error> for MainError {
fn from(e: std::io::Error) -> Self {
Self::IO(e)
}
}
impl From<std::num::ParseIntError> for MainError {
fn from(e: std::num::ParseIntError) -> Self {
Self::Parse(e)
}
}
Compiling above code give errors,
error[E0599]: no variant named `IO` found for type `MainError` in the current scope
--> src\main.rs:12:9
|
5 | enum MainError {
| -------------- variant `IO` not found here
...
12 | Self::IO(e)
| ^^^^^^^^ variant not found in `MainError`
|
= note: did you mean `MainError::IO`?
The error message is helpful (it indicates correct code, MainError::IO
). However, the first line of message is confusing, and E0599 does not help much to understand why this code is not working.
Can we improve error messages for such situations?