netzwork_api/
error.rs

1use std::error::Error;
2use std::fmt;
3// Define your custom error type
4#[derive(Debug)]
5pub enum NetzworkApiError {
6    HostIdentityError(String),
7    UnknownNetInterfaceId(String),
8    SomeProblem(String),
9}
10
11// Implement the Error trait for your custom error type
12impl Error for NetzworkApiError {}
13
14// Implement the Display trait to provide a user-friendly error message
15impl fmt::Display for NetzworkApiError {
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match self {
18            NetzworkApiError::HostIdentityError(msg) => {
19                write!(f, "Could not generate host UUID ({})", msg)
20            }
21            NetzworkApiError::UnknownNetInterfaceId(msg) => {
22                write!(f, "Could not identify Network Interface ({})", msg)
23            }
24            NetzworkApiError::SomeProblem(msg) => {
25                write!(f, "Something went wrong: {}", msg)
26            }
27        }
28    }
29}