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
use thiserror::Error;

/// Library errors.
#[derive(Error, Debug)]
#[error("libsystemd error: {msg}")]
pub struct SdError {
    pub(crate) kind: ErrorKind,
    pub(crate) msg: String,
}

impl From<&str> for SdError {
    fn from(arg: &str) -> Self {
        Self {
            kind: ErrorKind::Generic,
            msg: arg.to_string(),
        }
    }
}

impl From<String> for SdError {
    fn from(arg: String) -> Self {
        Self {
            kind: ErrorKind::Generic,
            msg: arg,
        }
    }
}

/// Markers for recoverable error kinds.
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum ErrorKind {
    Generic,
    SysusersUnknownType,
}