nullnet_libconfmon/
platform.rs

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
use crate::{Error, ErrorKind};

/// Represents the supported platforms.
#[derive(Clone, Copy, Debug)]
pub enum Platform {
    PfSense,
    OPNsense,
}

impl Platform {
    /// Converts a string representation into a `Platform` enum.
    ///
    /// # Parameters
    /// - `value`: A `String` containing the name of the platform.
    ///
    /// # Returns
    /// - `Ok(Platform)`: If the string matches a supported platform.
    /// - `Err(Error)`: If the string does not match any supported platform.
    ///
    /// # Errors
    /// Returns an `Error` with the kind `ErrorUnsupportedPlatform` if the input string is not recognized as a valid platform.
    pub fn from_string(value: &str) -> Result<Platform, Error> {
        match value.to_lowercase().as_str() {
            "pfsense" => Ok(Platform::PfSense),
            "opnsense" => Ok(Platform::OPNsense),
            _ => Err(Error {
                kind: ErrorKind::ErrorUnsupportedPlatform,
                message: format!("Unsupported platform: {value}"),
            }),
        }
    }
}