intiface_engine/
error.rs

1use buttplug::{core::errors::ButtplugError, server::ButtplugServerError};
2use std::{error::Error, fmt};
3
4#[derive(Debug)]
5pub struct IntifaceError {
6  reason: String,
7}
8
9impl IntifaceError {
10  pub fn new(error_msg: &str) -> Self {
11    Self {
12      reason: error_msg.to_owned(),
13    }
14  }
15}
16
17impl fmt::Display for IntifaceError {
18  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19    write!(f, "{}", self.reason)
20  }
21}
22
23impl Error for IntifaceError {
24  fn source(&self) -> Option<&(dyn Error + 'static)> {
25    None
26  }
27}
28
29#[derive(Debug)]
30pub enum IntifaceEngineError {
31  IoError(std::io::Error),
32  ButtplugServerError(ButtplugServerError),
33  ButtplugError(ButtplugError),
34  IntifaceError(IntifaceError),
35}
36
37impl From<std::io::Error> for IntifaceEngineError {
38  fn from(err: std::io::Error) -> Self {
39    IntifaceEngineError::IoError(err)
40  }
41}
42
43impl From<ButtplugError> for IntifaceEngineError {
44  fn from(err: ButtplugError) -> Self {
45    IntifaceEngineError::ButtplugError(err)
46  }
47}
48
49impl From<IntifaceError> for IntifaceEngineError {
50  fn from(err: IntifaceError) -> Self {
51    IntifaceEngineError::IntifaceError(err)
52  }
53}