Struct pact_models::path_exp::DocPath
source · pub struct DocPath { /* private fields */ }
Implementations§
source§impl DocPath
impl DocPath
sourcepub fn new(expr: impl Into<String>) -> Result<Self>
pub fn new(expr: impl Into<String>) -> Result<Self>
Construct a new document path from the provided string path
sourcepub fn new_unwrap(expr: &'static str) -> Self
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.
sourcepub fn empty() -> Self
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).
sourcepub fn first_field(&self) -> Option<&str>
pub fn first_field(&self) -> Option<&str>
Extract the string contents of the first Field token. For use with Header and Query DocPaths.
sourcepub fn last_field(&self) -> Option<&str>
pub fn last_field(&self) -> Option<&str>
Extract the string contents of the last Field token.
sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
If this path is the root path (it has only one element, the root token $
).
sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
The path is a wildcard path if it ends in a star (*
)
sourcepub fn path_weight(&self, path: &[&str]) -> (usize, usize)
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.
sourcepub fn matches_path(&self, path: &[&str]) -> bool
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).
sourcepub fn matches_path_exactly(&self, path: &[&str]) -> bool
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.
sourcepub fn join(&self, part: impl Into<String>) -> Self
pub fn join(&self, part: impl Into<String>) -> Self
Creates a new path by cloning this one and pushing the string onto the end
sourcepub fn push_field(&mut self, field: impl Into<String>) -> &mut Self
pub fn push_field(&mut self, field: impl Into<String>) -> &mut Self
Mutates this path by pushing a field value onto the end.
sourcepub fn push_index(&mut self, index: usize) -> &mut Self
pub fn push_index(&mut self, index: usize) -> &mut Self
Mutates this path by pushing an index value onto the end.
sourcepub fn push_star(&mut self) -> &mut Self
pub fn push_star(&mut self) -> &mut Self
Mutates this path by pushing a star value onto the end.
sourcepub fn push_star_index(&mut self) -> &mut Self
pub fn push_star_index(&mut self) -> &mut Self
Mutates this path by pushing a star index value onto the end.
sourcepub fn push(&mut self, path_token: PathToken) -> &mut Self
pub fn push(&mut self, path_token: PathToken) -> &mut Self
Mutates this path by pushing a path token onto the end.
sourcepub fn to_lower_case(&self) -> DocPath
pub fn to_lower_case(&self) -> DocPath
Returns a copy of this path will all parts lower case
sourcepub fn as_json_pointer(&self) -> Result<String>
pub fn as_json_pointer(&self) -> Result<String>
Converts this path into a JSON pointer RFC6901.
Trait Implementations§
source§impl<'de> Deserialize<'de> for DocPath
impl<'de> Deserialize<'de> for DocPath
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl Ord for DocPath
impl Ord for DocPath
source§impl PartialEq<DocPath> for DocPath
impl PartialEq<DocPath> for DocPath
source§impl PartialOrd<DocPath> for DocPath
impl PartialOrd<DocPath> for DocPath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for DocPath
impl StructuralEq for DocPath
Auto Trait Implementations§
impl RefUnwindSafe for DocPath
impl Send for DocPath
impl Sync for DocPath
impl Unpin for DocPath
impl UnwindSafe for DocPath
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.