1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::{
    fmt,
    string::FromUtf8Error,
};

#[derive(Debug, Clone)]
pub struct ClipboardError {
    message: String,
}

impl From<String> for ClipboardError {
    fn from(message: String) -> Self {
        Self { message }
    }
}
impl From<&str> for ClipboardError {
    fn from(message: &str) -> Self {
        Self { message: message.to_owned() }
    }
}

impl fmt::Display for ClipboardError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "clipboard error: {}", self.message)
    }
}

impl From<FromUtf8Error> for ClipboardError {
    fn from(_: FromUtf8Error) -> Self {
        ClipboardError::from("error interpreting as UTF8".to_string())
    }
}