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>) -> FieldPath
pub fn from_field(name: impl Into<String>) -> FieldPath
Create a path from a single field name
Sourcepub fn push_field(self, name: impl Into<String>) -> FieldPath
pub fn push_field(self, name: impl Into<String>) -> FieldPath
Add a field segment and return self (builder pattern)
Sourcepub fn push_index(self, idx: usize) -> FieldPath
pub fn push_index(self, idx: usize) -> FieldPath
Add an index segment and return self (builder pattern)
Sourcepub fn push_key(self, key: impl Into<String>) -> FieldPath
pub fn push_key(self, key: impl Into<String>) -> FieldPath
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>) -> FieldPath
pub fn child_field(&self, name: impl Into<String>) -> FieldPath
Create a child path with a field segment
Sourcepub fn child_index(&self, idx: usize) -> FieldPath
pub fn child_index(&self, idx: usize) -> FieldPath
Create a child path with an index segment
Sourcepub fn child_key(&self, key: impl Into<String>) -> FieldPath
pub fn child_key(&self, key: impl Into<String>) -> FieldPath
Create a child path with a key 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§
Source§impl<'de> Deserialize<'de> for FieldPath
impl<'de> Deserialize<'de> for FieldPath
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<FieldPath, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<FieldPath, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for FieldPath
impl Serialize for FieldPath
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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