cat_gateway/db/event/config/
key.rs

1//! Configuration Key
2
3use std::{fmt::Display, net::IpAddr};
4
5/// Configuration key
6#[derive(Debug, Clone, PartialEq)]
7pub(crate) enum ConfigKey {
8    /// Frontend general configuration.
9    Frontend,
10    /// Frontend configuration for a specific IP address.
11    FrontendForIp(IpAddr),
12}
13
14impl Display for ConfigKey {
15    fn fmt(
16        &self,
17        f: &mut std::fmt::Formatter<'_>,
18    ) -> std::fmt::Result {
19        match self {
20            ConfigKey::Frontend => write!(f, "config_key_frontend"),
21            ConfigKey::FrontendForIp(_) => write!(f, "config_key_frontend_ip"),
22        }
23    }
24}
25
26impl ConfigKey {
27    /// Convert a `ConfigKey` to its corresponding IDs.
28    pub(super) fn to_id(&self) -> (String, String, String) {
29        match self {
30            ConfigKey::Frontend => ("frontend".to_string(), String::new(), String::new()),
31            ConfigKey::FrontendForIp(ip) => {
32                ("frontend".to_string(), "ip".to_string(), ip.to_string())
33            },
34        }
35    }
36}