psocks/src/list/item.rs
2026-03-23 09:00:19 +02:00

28 lines
701 B
Rust

use log::debug;
#[derive(PartialEq, Eq, Hash)]
pub enum Item {
Ending(String),
Exact(String),
}
impl Item {
pub fn from_line(rule: &str) -> Self {
if let Some(item) = rule.strip_prefix(".") {
debug!("Add `{rule}` to the whitelist");
Self::Ending(item.to_string())
} else {
debug!("Add `{rule}` exact match to the whitelist");
Self::Exact(rule.to_string())
}
}
}
impl std::fmt::Display for Item {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Ending(s) => write!(f, ".{}", s),
Self::Exact(s) => write!(f, "{}", s),
}
}
}