streamdeck_oxide/
error.rs1use std::fmt;
6use std::error::Error as StdError;
7
8#[derive(Debug)]
10pub enum Error {
11 DeviceNotFound,
13 DeviceError(String),
15 RenderError(String),
17 ButtonIndexOutOfBounds(usize),
19 ElgatoError(elgato_streamdeck::StreamDeckError),
21 ImageError(String),
23 IoError(std::io::Error),
25 Custom(String),
27}
28
29impl fmt::Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Error::DeviceNotFound => write!(f, "Stream Deck device not found"),
33 Error::DeviceError(msg) => write!(f, "Device error: {}", msg),
34 Error::RenderError(msg) => write!(f, "Render error: {}", msg),
35 Error::ButtonIndexOutOfBounds(index) => {
36 write!(f, "Button index {} is out of bounds", index)
37 }
38 Error::ElgatoError(err) => write!(f, "Elgato Stream Deck error: {}", err),
39 Error::ImageError(msg) => write!(f, "Image error: {}", msg),
40 Error::IoError(err) => write!(f, "I/O error: {}", err),
41 Error::Custom(msg) => write!(f, "{}", msg),
42 }
43 }
44}
45
46impl StdError for Error {
47 fn source(&self) -> Option<&(dyn StdError + 'static)> {
48 match self {
49 Error::IoError(err) => Some(err),
50 Error::ElgatoError(_) => None, _ => None,
52 }
53 }
54}
55
56impl From<elgato_streamdeck::StreamDeckError> for Error {
57 fn from(err: elgato_streamdeck::StreamDeckError) -> Self {
58 Error::ElgatoError(err)
59 }
60}
61
62impl From<std::io::Error> for Error {
63 fn from(err: std::io::Error) -> Self {
64 Error::IoError(err)
65 }
66}
67
68impl From<String> for Error {
69 fn from(msg: String) -> Self {
70 Error::Custom(msg)
71 }
72}
73
74impl From<&str> for Error {
75 fn from(msg: &str) -> Self {
76 Error::Custom(msg.to_string())
77 }
78}
79
80pub type Result<T> = std::result::Result<T, Error>;