1use std::fmt::Display;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7 Rppal(rppal::gpio::Error),
8 Cdev(gpio_cdev::Error),
9}
10
11impl From<rppal::gpio::Error> for Error {
12 fn from(err: rppal::gpio::Error) -> Self {
13 Self::Rppal(err)
14 }
15}
16
17impl From<gpio_cdev::Error> for Error {
18 fn from(value: gpio_cdev::Error) -> Self {
19 Self::Cdev(value)
20 }
21}
22
23impl Display for Error {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self {
26 Self::Rppal(e) => write!(f, "Raspberry Pi GPIO error: {e}"),
27 Self::Cdev(e) => write!(f, "CDEV GPIO error: {e}"),
28 }
29 }
30}