libnotify_rs/api/
errors.rs1#[derive(Debug)]
3pub enum LibnotifyError {
4 InitError,
6 NulError(std::ffi::NulError),
8 NewNotificationError,
10 GerrorError(String),
12 AllocationError,
14}
15
16impl std::fmt::Display for LibnotifyError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 LibnotifyError::InitError => {
20 write!(f, "Libnotify failed to init")
21 }
22
23 LibnotifyError::NulError(_) => {
24 write!(f, "Argument contains a null terminator")
25 }
26
27 LibnotifyError::NewNotificationError => {
28 write!(f, "Notification constructor failed")
29 }
30
31 LibnotifyError::GerrorError(e) => {
32 write!(f, "Libnotify returned an error: {}", e)
33 }
34
35 LibnotifyError::AllocationError => {
36 write!(f, "Libnotify failed allocating memory")
37 }
38 }
39 }
40}
41
42impl std::error::Error for LibnotifyError {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 match self {
45 LibnotifyError::InitError => None,
46 LibnotifyError::NulError(nul_error) => Some(nul_error),
47 LibnotifyError::NewNotificationError => None,
48 LibnotifyError::GerrorError(_) => None,
49 LibnotifyError::AllocationError => None,
50 }
51 }
52}
53
54impl From<std::ffi::NulError> for LibnotifyError {
55 fn from(value: std::ffi::NulError) -> Self {
56 Self::NulError(value)
57 }
58}