Skip to main content

intiface_engine/
error.rs

1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2026 Nonpolynomial Labs LLC. All rights reserved.
4//
5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
6// for full license information.
7
8use buttplug_core::errors::ButtplugError;
9use buttplug_server::ButtplugServerError;
10use std::{error::Error, fmt};
11
12#[derive(Debug)]
13pub struct IntifaceError {
14  reason: String,
15}
16
17impl IntifaceError {
18  pub fn new(error_msg: &str) -> Self {
19    Self {
20      reason: error_msg.to_owned(),
21    }
22  }
23}
24
25impl fmt::Display for IntifaceError {
26  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27    write!(f, "{}", self.reason)
28  }
29}
30
31impl Error for IntifaceError {
32  fn source(&self) -> Option<&(dyn Error + 'static)> {
33    None
34  }
35}
36
37#[derive(Debug)]
38pub enum IntifaceEngineError {
39  IoError(std::io::Error),
40  ButtplugServerError(ButtplugServerError),
41  ButtplugError(ButtplugError),
42  IntifaceError(IntifaceError),
43}
44
45impl From<std::io::Error> for IntifaceEngineError {
46  fn from(err: std::io::Error) -> Self {
47    IntifaceEngineError::IoError(err)
48  }
49}
50
51impl From<ButtplugError> for IntifaceEngineError {
52  fn from(err: ButtplugError) -> Self {
53    IntifaceEngineError::ButtplugError(err)
54  }
55}
56
57impl From<IntifaceError> for IntifaceEngineError {
58  fn from(err: IntifaceError) -> Self {
59    IntifaceEngineError::IntifaceError(err)
60  }
61}