flake_edit/walk/
context.rs

1/// A helper for the [`Walker`], in order to hold context while traversing the tree.
2#[derive(Debug, Clone)]
3pub struct Context {
4    level: Vec<String>,
5}
6
7impl Context {
8    /// Returns the first (top) level of context, if any.
9    pub fn first(&self) -> Option<&str> {
10        self.level.first().map(|s| s.as_str())
11    }
12
13    /// Returns true if the first level matches the given string.
14    pub fn first_matches(&self, s: &str) -> bool {
15        self.first() == Some(s)
16    }
17
18    pub fn level(&self) -> &[String] {
19        &self.level
20    }
21}
22
23impl From<String> for Context {
24    fn from(s: String) -> Self {
25        Self { level: vec![s] }
26    }
27}