Skip to main content

FieldRoute

Struct FieldRoute 

Source
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

Source

pub fn new(steps: Vec<RouteStep>) -> Self

Builds a route from its steps.

Source

pub fn steps(&self) -> &[RouteStep]

The steps this route takes, in order.

Source

pub fn is_empty(&self) -> bool

Whether this route names nothing.

Source

pub fn holes(&self) -> usize

How many list indices Self::at wants.

Source

pub fn then(&self, step: RouteStep) -> Self

Extends this route by one step, which is how a walk builds one.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> FieldRoute

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldRoute

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FieldRoute

Source§

fn default() -> FieldRoute

Returns the “default value” for a type. Read more
Source§

impl Display for FieldRoute

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Dot notation with empty brackets: Creature List[].HitPoints.

The empty bracket is the point. A reader seeing [0] would take it for one element rather than every one.

Source§

impl From<&GffPath> for FieldRoute

Source§

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

Source§

fn from_str(route: &str) -> Result<Self, Self::Err>

Parses what Display renders.

A bracket has to be empty. Creature List[0].HitPoints is a GffPath and naming one element is what a route does not do, so it is refused rather than read as if the index were decoration.

Source§

type Err = RouteParseError

The associated error which can be returned from parsing.
Source§

impl Hash for FieldRoute

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for FieldRoute

Source§

fn cmp(&self, other: &FieldRoute) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for FieldRoute

Source§

fn eq(&self, other: &FieldRoute) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FieldRoute

Source§

fn partial_cmp(&self, other: &FieldRoute) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for FieldRoute

Source§

impl StructuralPartialEq for FieldRoute

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.