Skip to main content

asterust_junos/policy_options/
prefix_list.rs

1//! `prefix-list`
2//! `policy-options { prefix-list <name> { ... } }`.
3//!
4//! # See also
5//!
6//! - [prefix-list](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/prefix-list-edit-policy-options.html)
7
8use crate::{active_children, unquote};
9use asterust::config::ConfigLine;
10
11/// A `prefix-list <name>`.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct PrefixList {
15    pub name: String,
16    pub prefixes: Vec<String>,
17    pub apply_path: Option<String>,
18}
19
20pub(super) fn parse_prefix_list(name: &str, line: &ConfigLine) -> PrefixList {
21    let mut list = PrefixList {
22        name: name.to_string(),
23        prefixes: Vec::new(),
24        apply_path: None,
25    };
26    for child in active_children(line) {
27        if let Some(path) = child.arg("apply-path") {
28            list.apply_path = Some(unquote(path).to_string());
29        } else if !child.text.contains(' ') {
30            // Prefixes are the only statements without arguments; `apply-groups` and the like have a space.
31            list.prefixes.push(child.text.clone());
32        }
33    }
34    list
35}