vnetod/src/domain.rs

29 lines
630 B
Rust

pub mod switch;
#[derive(Debug, Clone, PartialEq, Eq)]
struct Section {
namespace: Option<String>,
name: String,
}
impl Section {
fn new(name: &str) -> Self {
Self {
name: name.to_string(),
namespace: None,
}
}
fn with_namespace(namespace: &str, name: &str) -> Self {
Self {
name: name.to_string(),
namespace: Some(namespace.to_string()),
}
}
fn parse(s: &str) -> Self {
let s = s.trim();
s.split_once(':')
.map_or_else(|| Self::new(s), |(ns, name)| Self::with_namespace(ns, name))
}
}