pub struct FieldRoute { /* private fields */ }Expand description
Where a field sits, from the root of the view that declares it.
Ordered and hashable, so a set of findings or changed locations can be keyed on one without a string in the middle.
Implementations§
Source§impl FieldRoute
impl FieldRoute
Sourcepub fn then(&self, step: RouteStep) -> Self
pub fn then(&self, step: RouteStep) -> Self
Extends this route by one step, which is how a walk builds one.
Sourcepub fn at(&self, indices: &[usize]) -> Result<GffPath, RouteError>
pub fn at(&self, indices: &[usize]) -> Result<GffPath, RouteError>
Turns this route into an address in one file.
indices supplies one element index per RouteStep::Element, in the
order they appear. A route through no list takes an empty slice.
§Errors
RouteError::IndexCount when the count does not match. Taking a
slice rather than one index is what lets a route through two nested
lists work, and mismatching the count is the mistake that makes.
Sourcepub fn field_in<T: HasSchema>(&self) -> Result<&'static Field, RouteError>
pub fn field_in<T: HasSchema>(&self) -> Result<&'static Field, RouteError>
The field this route names in T’s schema.
What turns a route from a claim into an anchor. A route naming a label no view declares is a typo that would otherwise point at nothing and say nothing, and the field it hands back carries the entry a caller needs anyway: what the field holds, whether the engine reads it, and what its absence means.
§Errors
RouteError naming how far the walk got, so a long route says which
step was wrong rather than that the whole thing was.
Sourcepub fn entries_in<T: HasSchema>(
&self,
) -> Result<Vec<&'static Field>, RouteError>
pub fn entries_in<T: HasSchema>( &self, ) -> Result<Vec<&'static Field>, RouteError>
Every entry declared for the field this route names.
One, ordinarily. Two when the route ends inside a split and both arms
declare the label: List[].TemplateResRef is declared by the templated
arm and by the saved one, with different write rules, and which applies
depends on the selector’s value in a given file. The address is the
same either way, so a tree, a diff row and a write-back can use the
route while only a consumer wanting the entry has to choose.
§Errors
RouteError naming how far the walk got.
Sourcepub fn field_under(
&self,
parts: &[&'static [Field]],
) -> Result<Vec<&'static Field>, RouteError>
pub fn field_under( &self, parts: &[&'static [Field]], ) -> Result<Vec<&'static Field>, RouteError>
The field this route names under an explicit set of schema parts.
Parts rather than one slice throughout, because that is how a schema holds a type that flattens a shared block: the block stays one declaration and the container points at it.
A list’s elements are looked up across the element schema and both
arms of a Split together. Which arm a file takes
depends on a sibling’s value, which a route does not carry, so a label
declared by one arm resolves and one declared by both is refused.
§Errors
RouteError::NoSuchField when parts declares no such label at that
point, RouteError::NotAList when the route indexes something that
is not one, RouteError::NotAStruct when it descends into something
with no fields under it, and RouteError::NamesNoField when the
route ends at a list element rather than at something the element
holds. An empty route is that last one.
RouteError::AmbiguousArm when both arms of a Split
declare the label. Which arm a file takes turns on a sibling’s value,
which a route does not carry, so this is refused rather than guessed.
RouteError::IndexCount when the route’s index count does not match
what its steps need. That is a malformed route rather than a schema
that disagrees with it.
Trait Implementations§
Source§impl Clone for FieldRoute
impl Clone for FieldRoute
Source§fn clone(&self) -> FieldRoute
fn clone(&self) -> FieldRoute
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldRoute
impl Debug for FieldRoute
Source§impl Default for FieldRoute
impl Default for FieldRoute
Source§fn default() -> FieldRoute
fn default() -> FieldRoute
Source§impl Display for FieldRoute
impl Display for FieldRoute
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.
Source§impl FromStr for FieldRoute
impl FromStr for FieldRoute
Source§impl Hash for FieldRoute
impl Hash for FieldRoute
Source§impl Ord for FieldRoute
impl Ord for FieldRoute
Source§fn cmp(&self, other: &FieldRoute) -> Ordering
fn cmp(&self, other: &FieldRoute) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FieldRoute
impl PartialEq for FieldRoute
Source§fn eq(&self, other: &FieldRoute) -> bool
fn eq(&self, other: &FieldRoute) -> bool
self and other values to be equal, and is used by ==.