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
use std::error::Error;
use std::fmt;
// Define your custom error type
#[derive(Debug)]
pub enum NetzworkApiError {
    HostIdentityError(String),
    UnknownNetInterfaceId(String),
    SomeProblem(String),
}

// Implement the Error trait for your custom error type
impl Error for NetzworkApiError {}

// Implement the Display trait to provide a user-friendly error message
impl fmt::Display for NetzworkApiError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            NetzworkApiError::HostIdentityError(msg) => {
                write!(f, "Could not generate host UUID ({})", msg)
            }
            NetzworkApiError::UnknownNetInterfaceId(msg) => {
                write!(f, "Could not identify Network Interface ({})", msg)
            }
            NetzworkApiError::SomeProblem(msg) => {
                write!(f, "Something went wrong: {}", msg)
            }
        }
    }
}