1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::{borrow::Cow, error::Error, fmt};

/// [Error] while mapping between types
#[derive(Debug)]
pub struct MapperError(Cow<'static, str>);
impl MapperError {
    pub(crate) fn new(message: impl Into<Cow<'static, str>>) -> Self {
        Self(message.into())
    }

    pub(crate) fn from(error: impl fmt::Display) -> Self {
        Self::new(error.to_string())
    }
}

impl fmt::Display for MapperError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl Error for MapperError {}