pub struct ElementPath { /* private fields */ }Expand description
Identify an element by its path from the top level down; the empty path is the root level, never an element.
Implementations§
Source§impl ElementPath
impl ElementPath
Sourcepub fn from_segments<I, S>(segments: I) -> Self
pub fn from_segments<I, S>(segments: I) -> Self
Build a path from its segments, outermost first.
Sourcepub fn child(&self, segment: impl Into<String>) -> Self
pub fn child(&self, segment: impl Into<String>) -> Self
Return the path of the child segment one level below this path.
Sourcepub fn enclosing_level(&self) -> Self
pub fn enclosing_level(&self) -> Self
Return the level this path is drawn in: its parent, or the root for a top-level element and for the root itself.
Sourcepub fn is_ancestor_of(&self, other: &Self) -> bool
pub fn is_ancestor_of(&self, other: &Self) -> bool
Tell whether self is a proper prefix of other.
Tell whether other is self, its ancestor or its descendant.
Sourcepub fn lowest_common_ancestor(&self, other: &Self) -> Self
pub fn lowest_common_ancestor(&self, other: &Self) -> Self
Return the longest common prefix of both paths.
Sourcepub fn ancestors(&self) -> impl Iterator<Item = Self> + '_
pub fn ancestors(&self) -> impl Iterator<Item = Self> + '_
Yield every proper non-root prefix, outermost first: the elements that must exist for this one to exist.
Sourcepub fn ancestor_or_self_at_depth(&self, depth: usize) -> Self
pub fn ancestor_or_self_at_depth(&self, depth: usize) -> Self
Return the prefix of depth segments: the ancestor at that depth, or the path itself at its own depth.
Sourcepub fn truncated_to_depth(&self, depth: usize) -> Self
pub fn truncated_to_depth(&self, depth: usize) -> Self
Return this path truncated to at most depth segments: its ancestor at that depth, or itself when it is no deeper.
Sourcepub fn is_component_id(text: &str) -> bool
pub fn is_component_id(text: &str) -> bool
Tell whether text follows the component id rules: ASCII letters, digits, _ and single inner -, starting with a letter or _.