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
54
55
56
57
58
use std::fmt::Display;
use zbus::zvariant::OwnedValue;
#[derive(Debug)]
pub enum Error {
DBusConnectionFail(zbus::Error),
DBusInvalidPath(zbus::zvariant::Error),
ListenPropertyChangeFail(zbus::Error),
ParsePropertyChangeFail(zbus::Error),
QueryPropertyFail(zbus::fdo::Error),
StartFail(zbus::Error),
TimeUsageFail(&'static str, Box<OwnedValue>, Box<OwnedValue>),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
match self {
Self::DBusConnectionFail(e) => {
write!(f, "cannot connect to dbus: {}", e)
}
Self::DBusInvalidPath(e) => {
write!(f, "cannot get a dbus path: {}", e)
}
Self::StartFail(e) => {
write!(f, "cannot start transient service: {}", e)
}
Self::ListenPropertyChangeFail(e) => {
write!(f, "cannot listen property change events: {}", e)
}
Self::ParsePropertyChangeFail(e) => {
write!(f, "cannot parse property changes: {}", e)
}
Self::QueryPropertyFail(e) => {
write!(f, "cannot parse property changes: {}", e)
}
Self::TimeUsageFail(what, t0, t1) => {
write!(f, "cannot calculate {} time usage: ", what)?;
write!(f, "t0 = {:?}, t1 = {:?}", t0, t1)
}
}
}
}
impl std::error::Error for Error {}