pub struct PathBuf { /* private fields */ }Expand description
An owned, validated path for hierarchical document access.
PathBuf provides a type-safe way to construct and manipulate paths
for accessing nested structures in CRDT documents. It validates that
paths are well-formed and provides efficient access to path component.
§Examples
// Create from string (automatically normalized)
let path = PathBuf::from_str("user.profile.name")?;
// Build incrementally (infallible)
let path = PathBuf::new()
.push("user")
.push("profile")
.push("name");
// Get components
let components: Vec<&str> = path.components().collect();
assert_eq!(components, vec!["user", "profile", "name"]);Implementations§
Source§impl PathBuf
impl PathBuf
Sourcepub fn from_component(component: Component) -> Self
pub fn from_component(component: Component) -> Self
Creates a path from a single component.
Sourcepub fn push(self, path: impl AsRef<str>) -> Self
pub fn push(self, path: impl AsRef<str>) -> Self
Adds a path to the end of this path.
This method accepts both strings and Path types, normalizing the input. It’s infallible and handles all path joining cases through normalization.
§Examples
// Push strings
let path = PathBuf::new().push("user").push("profile");
assert_eq!(path.as_str(), "user.profile");
// Push Path types
let suffix = PathBuf::from_str("name.value").unwrap();
let path = PathBuf::new().push("user").push(&suffix);
assert_eq!(path.as_str(), "user.name.value");Sourcepub fn push_component(self, component: Component) -> Self
pub fn push_component(self, component: Component) -> Self
Adds a validated component to the end of this path.
Sourcepub fn components(&self) -> impl Iterator<Item = &str>
pub fn components(&self) -> impl Iterator<Item = &str>
Returns an iterator over the path components as string slices.
Methods from Deref<Target = Path>§
Sourcepub fn components(&self) -> impl Iterator<Item = &str>
pub fn components(&self) -> impl Iterator<Item = &str>
Returns an iterator over the path components as string slices.
Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
Returns the last component of the path, or None if empty.
Sourcepub fn to_path_buf(&self) -> PathBuf
pub fn to_path_buf(&self) -> PathBuf
Converts this Path to an owned PathBuf.
Trait Implementations§
Source§impl FromStrResult for PathBuf
impl FromStrResult for PathBuf
impl Eq for PathBuf
impl StructuralPartialEq for PathBuf
Auto Trait Implementations§
impl Freeze for PathBuf
impl RefUnwindSafe for PathBuf
impl Send for PathBuf
impl Sync for PathBuf
impl Unpin for PathBuf
impl UnwindSafe for PathBuf
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.