Struct pact_models::path_exp::DocPath

source ·
pub struct DocPath { /* private fields */ }

Implementations§

source§

impl DocPath

source

pub fn new(expr: impl Into<String>) -> Result<Self>

Construct a new document path from the provided string path

source

pub fn new_unwrap(expr: &'static str) -> Self

Infallible construction for when the expression is statically known, intended for unit tests.

Invalid expressions will still cause panics.

source

pub fn empty() -> Self

Construct a new DocPath with an empty expression.

Warning: do not call any of the push_* methods on this DocPath, as that would create an expression with invalid syntax (because it would be missing the Root token).

source

pub fn root() -> Self

Construct a new DocPath with the Root token.

source

pub fn tokens(&self) -> &Vec<PathToken>

Return the list of tokens that comprise this path.

source

pub fn len(&self) -> usize

Return the length, in parsed tokens.

source

pub fn first_field(&self) -> Option<&str>

Extract the string contents of the first Field token. For use with Header and Query DocPaths.

source

pub fn last_field(&self) -> Option<&str>

Extract the string contents of the last Field token.

source

pub fn is_root(&self) -> bool

If this path is the root path (it has only one element, the root token $).

source

pub fn is_wildcard(&self) -> bool

The path is a wildcard path if it ends in a star (*)

source

pub fn path_weight(&self, path: &[&str]) -> (usize, usize)

Calculates the path weight for this path expression and a given path. Returns a tuple of the calculated weight and the number of path tokens matched.

source

pub fn matches_path(&self, path: &[&str]) -> bool

If this path matches the given path. It will match if the calculated path weight is greater than zero (which means at least one token matched).

source

pub fn matches_path_exactly(&self, path: &[&str]) -> bool

If the path matches the given path (the calculated path weight is greater than zero) and both paths have the same length.

source

pub fn join(&self, part: impl Into<String>) -> Self

Creates a new path by cloning this one and pushing the string onto the end

source

pub fn push_field(&mut self, field: impl Into<String>) -> &mut Self

Mutates this path by pushing a field value onto the end.

source

pub fn push_index(&mut self, index: usize) -> &mut Self

Mutates this path by pushing an index value onto the end.

source

pub fn push_star(&mut self) -> &mut Self

Mutates this path by pushing a star value onto the end.

source

pub fn push_star_index(&mut self) -> &mut Self

Mutates this path by pushing a star index value onto the end.

source

pub fn push(&mut self, path_token: PathToken) -> &mut Self

Mutates this path by pushing a path token onto the end.

source

pub fn push_path(&mut self, path: &DocPath) -> &mut Self

Mutates this path by pushing another path onto the end. Will drop the root marker from the other path

source

pub fn to_vec(&self) -> Vec<String>

Convert this path to a vector of strings

source

pub fn parent(&self) -> Option<Self>

Return the parent path from this one

source

pub fn to_lower_case(&self) -> DocPath

Returns a copy of this path will all parts lower case

source

pub fn as_json_pointer(&self) -> Result<String>

Converts this path into a JSON pointer RFC6901.

Trait Implementations§

source§

impl Clone for DocPath

source§

fn clone(&self) -> DocPath

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for DocPath

source§

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

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

impl<'de> Deserialize<'de> for DocPath

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for DocPath

source§

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

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

impl From<&DocPath> for String

source§

fn from(doc_path: &DocPath) -> String

Converts to this type from the input type.
source§

impl From<DocPath> for String

source§

fn from(doc_path: DocPath) -> String

Converts to this type from the input type.
source§

impl Hash for DocPath

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 DocPath

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

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

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

impl PartialEq for DocPath

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for DocPath

source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for DocPath

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<String> for DocPath

§

type Error = Error

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

fn try_from(path: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for DocPath

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> 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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> Fmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

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§

default 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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,