use crate::{active_children, split_name};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct MplsPath {
pub name: String,
pub hops: Vec<MplsPathHop>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct MplsPathHop {
pub address: String,
pub qualifier: Option<String>,
}
pub(super) fn parse_path(name: &str, path: &ConfigLine) -> MplsPath {
MplsPath {
name: name.to_string(),
hops: active_children(path)
.map(|hop| {
let (address, rest) = split_name(&hop.text);
MplsPathHop {
address: address.to_string(),
qualifier: Some(rest).filter(|q| !q.is_empty()).map(str::to_string),
}
})
.collect(),
}
}