pub struct GffPath { /* private fields */ }Expand description
An address into a GFF tree, such as ClassList[0].Class.
Rendering gives the same dot notation rakata-lint already prints in
LintDiagnostic.fields, so a consumer wanting to navigate to a finding
rather than display it has one address type to use for both.
Implementations§
Source§impl GffPath
impl GffPath
Sourcepub fn new(segments: Vec<GffPathSegment>) -> Self
pub fn new(segments: Vec<GffPathSegment>) -> Self
Creates a path from its segments.
Sourcepub fn segments(&self) -> &[GffPathSegment]
pub fn segments(&self) -> &[GffPathSegment]
The steps this path takes, in order.
Sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
This path with its last step dropped, or None when it has none.
What a list mutation records against: appending to or removing from a list changes the list, and the index the caller named is not where the change is once the siblings have shifted.
Sourcepub fn then(&self, segment: GffPathSegment) -> Self
pub fn then(&self, segment: GffPathSegment) -> Self
Extends this path by one step, which is how a walk builds one.
Sourcepub fn starts_with(&self, prefix: &Self) -> bool
pub fn starts_with(&self, prefix: &Self) -> bool
Whether prefix names this node or one of its ancestors.
Segment by segment rather than over the rendered text, and that is the
whole reason this is a method. "ItemList".starts_with("ItemLis") is
true and ItemList is not under ItemLis, so a prefix test written on
the strings answers yes for a sibling whose label merely begins the same
way. Comparing segments cannot make that mistake, because a label is
matched whole.
Reflexive, matching the slice method it is built on: a path starts with itself. Callers wanting proper descendants exclude equality themselves, which is what the tree does when deciding whether a collapsed node hides a row, since a collapsed node has to keep drawing itself.
Ordering makes this cheap to use over a set. GffPath sorts by
segments, so every descendant of a path sorts contiguously after it with
nothing able to sort between; a BTreeMap of changes answers “anything
under here” with one range and this test on the first entry.
Trait Implementations§
Source§impl From<&GffPath> for FieldRoute
impl From<&GffPath> for FieldRoute
Source§fn from(path: &GffPath) -> Self
fn from(path: &GffPath) -> Self
The route a path in one file takes through every file.
The inverse of FieldRoute::at, and lossy in the direction it has to
be: Creature List[3].HitPoints becomes Creature List[].HitPoints,
because which element was in hand is a fact about the file and a route
carries only facts about the format.
Total, and there is nothing here that could fail. Every segment maps to
exactly one step, so a path that addresses nothing at all still projects
to the route it would have taken. Whether the schema declares anything
there is the separate question FieldRoute::field_in answers, and
keeping the two apart is what lets a caller ask about a node the file
carries and no view models.