Hello,
I'm currently trying to create a custom std::error::Error enum.
But when MyError is used in Generic, I get the following compilation error:
use std::{error::Error, fmt};
#[derive(Debug)]
enum MyError {
Hello
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
panic!("hello");
}
}
impl Error for MyError {
fn description(&self) -> &str {
panic!("hello");
}
}
fn test<E>()-> Result<(), E>
where
E: Error
{
Err(MyError::Hello)
}
24 | Err(MyError::Hello)
| --- ^^^^^^^^^^^^^^ expected type parameter `E`, found enum `MyError`
| |
| arguments to this enum variant are incorrect
|
= note: expected type parameter `E`
found enum `MyError`
I have started to learn rust recently. I would be grateful if you could help me on this error. I've seen a lot of similar issues but for me it's difficult to relate to my problem.