nullnet_libconfmon/
platform.rs

1use crate::{Error, ErrorKind};
2
3/// Represents the supported platforms.
4#[derive(Clone, Copy, Debug)]
5pub enum Platform {
6    PfSense,
7    OPNsense,
8}
9
10impl Platform {
11    /// Converts a string representation into a `Platform` enum.
12    ///
13    /// # Parameters
14    /// - `value`: A `String` containing the name of the platform.
15    ///
16    /// # Returns
17    /// - `Ok(Platform)`: If the string matches a supported platform.
18    /// - `Err(Error)`: If the string does not match any supported platform.
19    ///
20    /// # Errors
21    /// Returns an `Error` with the kind `ErrorUnsupportedPlatform` if the input string is not recognized as a valid platform.
22    pub fn from_string(value: &str) -> Result<Platform, Error> {
23        match value.to_lowercase().as_str() {
24            "pfsense" => Ok(Platform::PfSense),
25            "opnsense" => Ok(Platform::OPNsense),
26            _ => Err(Error {
27                kind: ErrorKind::ErrorUnsupportedPlatform,
28                message: format!("Unsupported platform: {value}"),
29            }),
30        }
31    }
32}