pub struct Path(/* private fields */);Expand description
A complete path into a JSON structure.
Paths are immutable sequences of segments. Use builder methods to construct paths incrementally.
§Examples
use tirea_state::Path;
let path = Path::root().key("users").index(0).key("name");
assert_eq!(path.len(), 3);Implementations§
Source§impl Path
impl Path
Sourcepub fn from_segments(segments: Vec<Seg>) -> Self
pub fn from_segments(segments: Vec<Seg>) -> Self
Create a path from a vector of segments.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a path with pre-allocated capacity.
Sourcepub fn key(self, k: impl Into<String>) -> Self
pub fn key(self, k: impl Into<String>) -> Self
Append a key segment and return self (builder pattern).
Sourcepub fn index(self, i: usize) -> Self
pub fn index(self, i: usize) -> Self
Append an index segment and return self (builder pattern).
Sourcepub fn push_index(&mut self, i: usize)
pub fn push_index(&mut self, i: usize)
Push an index segment onto the path (mutating).
Sourcepub fn segments_mut(&mut self) -> &mut Vec<Seg>
pub fn segments_mut(&mut self) -> &mut Vec<Seg>
Get a mutable reference to the segments.
Sourcepub fn with_segment(&self, seg: Seg) -> Path
pub fn with_segment(&self, seg: Seg) -> Path
Append a segment and return a new path (non-mutating builder).
Sourcepub fn is_prefix_of(&self, other: &Path) -> bool
pub fn is_prefix_of(&self, other: &Path) -> bool
Check if this path is a prefix of another path.
A path is a prefix of another if all of its segments match the beginning of the other path’s segments.
§Examples
use tirea_state::path;
let parent = path!("user");
let child = path!("user", "name");
assert!(parent.is_prefix_of(&child));
assert!(!child.is_prefix_of(&parent));
assert!(parent.is_prefix_of(&parent)); // A path is a prefix of itselfSourcepub fn starts_with(&self, prefix: &Path) -> bool
pub fn starts_with(&self, prefix: &Path) -> bool
Check if this path starts with another path.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Path
impl<'de> Deserialize<'de> for Path
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromIterator<Seg> for Path
impl FromIterator<Seg> for Path
Source§impl<'a> IntoIterator for &'a Path
impl<'a> IntoIterator for &'a Path
Source§impl IntoIterator for Path
impl IntoIterator for Path
Source§impl Ord for Path
impl Ord for Path
Source§impl PartialOrd for Path
impl PartialOrd for Path
impl Eq for Path
impl StructuralPartialEq for Path
Auto Trait Implementations§
impl Freeze for Path
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnsafeUnpin for Path
impl UnwindSafe for Path
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