pub struct Path { /* private fields */ }Expand description
A borrowed, validated path for hierarchical document access.
Path is the borrowed counterpart to PathBuf, similar to how &str
relates to String. It provides efficient read-only access to path
components without allocation.
This type is unsized and must always be used behind a reference.
Implementations§
Source§impl Path
impl Path
Sourcepub fn new(s: &str) -> &Path
pub fn new(s: &str) -> &Path
Creates a Path from a string slice.
This is a zero-cost operation that wraps the string without validation or normalization. Normalization happens during path processing operations when needed.
This follows the same pattern as std::path::Path::new().
Sourcepub unsafe fn from_str_unchecked(s: &str) -> &Path
pub unsafe fn from_str_unchecked(s: &str) -> &Path
Creates a Path from a string without validation.
§Safety
The caller must ensure that the string is a valid path according to our validation rules:
- No leading or trailing dots
- No empty components (consecutive dots)
- Components may not contain dots
This is primarily intended for use with compile-time validated string literals.
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§
impl Eq for Path
impl StructuralPartialEq for Path
Auto Trait Implementations§
impl Freeze for Path
impl RefUnwindSafe for Path
impl Send for Path
impl !Sized for Path
impl Sync for Path
impl Unpin 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
§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.