pub struct FieldPath { /* private fields */ }Expand description
A path to a field in a nested structure.
§Example
use skp_validator_core::FieldPath;
// Build path: user.addresses[0].city
let path = FieldPath::new()
.push_field("user")
.push_field("addresses")
.push_index(0)
.push_field("city");
assert_eq!(path.to_string(), "user.addresses[0].city");Implementations§
Source§impl FieldPath
impl FieldPath
Sourcepub fn from_field(name: impl Into<String>) -> Self
pub fn from_field(name: impl Into<String>) -> Self
Create a path from a single field name
Sourcepub fn push_field(self, name: impl Into<String>) -> Self
pub fn push_field(self, name: impl Into<String>) -> Self
Add a field segment and return self (builder pattern)
Sourcepub fn push_index(self, idx: usize) -> Self
pub fn push_index(self, idx: usize) -> Self
Add an index segment and return self (builder pattern)
Sourcepub fn push_key(self, key: impl Into<String>) -> Self
pub fn push_key(self, key: impl Into<String>) -> Self
Add a key segment and return self (builder pattern)
Sourcepub fn append_field(&mut self, name: impl Into<String>)
pub fn append_field(&mut self, name: impl Into<String>)
Add a field segment in place
Sourcepub fn append_index(&mut self, idx: usize)
pub fn append_index(&mut self, idx: usize)
Add an index segment in place
Sourcepub fn append_key(&mut self, key: impl Into<String>)
pub fn append_key(&mut self, key: impl Into<String>)
Add a key segment in place
Sourcepub fn segments(&self) -> &[PathSegment]
pub fn segments(&self) -> &[PathSegment]
Get the segments as a slice
Sourcepub fn last(&self) -> Option<&PathSegment>
pub fn last(&self) -> Option<&PathSegment>
Get the last segment (leaf field name)
Sourcepub fn last_field_name(&self) -> Option<&str>
pub fn last_field_name(&self) -> Option<&str>
Get the field name of the last segment if it’s a Field
Sourcepub fn child_field(&self, name: impl Into<String>) -> Self
pub fn child_field(&self, name: impl Into<String>) -> Self
Create a child path with a field segment
Sourcepub fn child_index(&self, idx: usize) -> Self
pub fn child_index(&self, idx: usize) -> Self
Create a child path with an index segment
Sourcepub fn to_dot_notation(&self) -> String
pub fn to_dot_notation(&self) -> String
Convert to a dot-notation string
Sourcepub fn to_json_pointer(&self) -> String
pub fn to_json_pointer(&self) -> String
Convert to a JSON pointer string (RFC 6901)
Trait Implementations§
impl Eq for FieldPath
impl StructuralPartialEq for FieldPath
Auto Trait Implementations§
impl Freeze for FieldPath
impl RefUnwindSafe for FieldPath
impl Send for FieldPath
impl Sync for FieldPath
impl Unpin for FieldPath
impl UnwindSafe for FieldPath
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
Mutably borrows from an owned value. Read more