Help understanding a error

⚓ rust    📅 2025-05-14    👤 surdeus    👁️ 3      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Help understanding a error

I am trying to use wrapper around different kind of errors so I don't have to worry about returning specific errors for each function.

Here is implementation I managed to dig out from ai code tools.

use std::{error::Error as StdError, fmt, io};
use crossterm::ErrorKind as CrosstermErrorKind;

#[derive(Debug)]
pub enum EditorError {
    Io(io::Error),
    Crossterm(CrosstermErrorKind),
    ConfigError(Box<dyn StdError + Send + Sync>),
}

impl fmt::Display for EditorError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            EditorError::Io(e) => write!(f, "IO error: {}", e),
            EditorError::Crossterm(e) => write!(f, "Crossterm error: {}", e),
            EditorError::ConfigError(e) => write!(f, "Config error: {}", e),
        }
    }
}

impl StdError for EditorError {}

impl From<io::Error> for EditorError {
    fn from(err: io::Error) -> Self {
        EditorError::Io(err)
    }
}

impl From<CrosstermErrorKind> for EditorError {
    fn from(err: CrosstermErrorKind) -> Self {
        EditorError::Crossterm(err)
    }
}

impl From<Box<dyn StdError + Send + Sync>> for EditorError {
    fn from(err: Box<dyn StdError + Send + Sync>) -> Self {
        EditorError::ConfigError(err)
    }
}

pub type Result<T> = std::result::Result<T, EditorError>;

I get this error ?

error[E0119]: conflicting implementations of trait `From<std::io::Error>` for type `EditorError`
  --> src\utils\error.rs:29:1
   |
23 | impl From<io::Error> for EditorError {
   | ------------------------------------ first implementation here
...
29 | impl From<CrosstermErrorKind> for EditorError {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `EditorError`****

How is io:Error same as CrosstermErrorKind. Is it due to some aliasing. Is this kind of overloading not allowed. I am new to rust so I am trying to understand. Any help will be greatly appreciated. Also any pointers to how to in general debug these kind of issues ?

2 posts - 2 participants

Read full topic

🏷️ rust_feed