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>
impl<'p> Path<'p>
Sourcepub fn matches(&self, pattern: &[&str]) -> bool
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§
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> 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<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more