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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use buttplug::{core::errors::ButtplugError, server::ButtplugServerError};
use std::{error::Error, fmt};

#[derive(Debug)]
pub struct IntifaceError {
  reason: String,
}

impl IntifaceError {
  pub fn new(error_msg: &str) -> Self {
    Self {
      reason: error_msg.to_owned(),
    }
  }
}

impl fmt::Display for IntifaceError {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(f, "{}", self.reason)
  }
}

impl Error for IntifaceError {
  fn source(&self) -> Option<&(dyn Error + 'static)> {
    None
  }
}

#[derive(Debug)]
pub enum IntifaceEngineError {
  IoError(std::io::Error),
  ButtplugServerError(ButtplugServerError),
  ButtplugError(ButtplugError),
  IntifaceError(IntifaceError),
}

impl From<std::io::Error> for IntifaceEngineError {
  fn from(err: std::io::Error) -> Self {
    IntifaceEngineError::IoError(err)
  }
}

impl From<ButtplugError> for IntifaceEngineError {
  fn from(err: ButtplugError) -> Self {
    IntifaceEngineError::ButtplugError(err)
  }
}

impl From<IntifaceError> for IntifaceEngineError {
  fn from(err: IntifaceError) -> Self {
    IntifaceEngineError::IntifaceError(err)
  }
}