Skip to main content

Path

Enum Path 

Source
pub enum Path<'p> {
    Root,
    Index(&'p Path<'p>, usize),
    Key(&'p Path<'p>, CompactString),
}
Expand description

A path represented by nodes that borrow their parents.

Callbacks receive a temporary path. Path::matches compares its segments without allocating. Display prints keys separated by dots and indices in brackets, omitting the root prefix for non-root paths.

Variants§

§

Root

The root value, displayed as <root>.

§

Index(&'p Path<'p>, usize)

A sequence element with its parent path and zero-based index.

§

Key(&'p Path<'p>, CompactString)

A map or struct value with its parent path and key.

Implementations§

Source§

impl<'p> Path<'p>

Source

pub fn matches(&self, pattern: &[&str]) -> bool

Matches the entire path against root-to-leaf segments without allocating.

The first segment must be "<root>". "*" matches exactly one key or sequence index, but cannot replace the root segment. Indices are compared as usize values. Dots and brackets inside keys are literal; "*" has no escape syntax. Matching takes linear time and constant auxiliary space.

use serde_unknown::Path;

let root = Path::Root;
let items = Path::Key(&root, "items".into());
let entry = Path::Index(&items, 3);
let extra = Path::Key(&entry, "extra".into());

assert!(extra.matches(&["<root>", "items", "3", "extra"]));
assert!(extra.matches(&["<root>", "items", "*", "extra"]));
assert!(!extra.matches(&["items", "3", "extra"]));

Trait Implementations§

Source§

impl<'p> Debug for Path<'p>

Source§

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

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

impl Display for Path<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'p> Freeze for Path<'p>

§

impl<'p> RefUnwindSafe for Path<'p>

§

impl<'p> Send for Path<'p>

§

impl<'p> Sync for Path<'p>

§

impl<'p> Unpin for Path<'p>

§

impl<'p> UnsafeUnpin for Path<'p>

§

impl<'p> UnwindSafe for Path<'p>

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<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> ToCompactString for T
where T: Display,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.