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
use pulse::error::PAErr;
use crate::controllers::error::ControllerError;
#[derive(Debug, Clone)]
pub enum Error {
Connect(String),
Operation(String),
PulseAudio(String),
Controller(ControllerError),
}
impl std::error::Error for Error {}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Connect(e) => f.write_str(&format!("ConnectError: {}", e)),
Self::Operation(e) => f.write_str(&format!("OperationError: {}", e)),
Self::PulseAudio(e) => f.write_str(&format!("PulseAudioError: {}", e)),
Self::Controller(e) => f.write_str(&format!("ControllerError: {}", e)),
}
}
}
impl From<PAErr> for Error {
fn from(error: PAErr) -> Self {
Self::PulseAudio(
error
.to_string()
.unwrap_or_else(|| "Unknown error".to_string()),
)
}
}