pub struct RelPath(/* private fields */);Expand description
A file system path that is guaranteed to be relative and normalized.
This type can be used to represent paths in a uniform way, regardless of whether they refer to Windows or POSIX file systems, and regardless of the host platform.
Internally, paths are stored in POSIX (‘/’-delimited) format, but they can be displayed in either POSIX or Windows format.
Relative paths are also guaranteed to be valid unicode.
Implementations§
Source§impl RelPath
impl RelPath
Sourcepub fn new<'a>(path: &'a Path, path_style: PathStyle) -> Result<Cow<'a, Self>>
pub fn new<'a>(path: &'a Path, path_style: PathStyle) -> Result<Cow<'a, Self>>
Converts a path with a given style into a RelPath.
Returns an error if the path is absolute, or is not valid unicode.
This method will normalize the path by removing . components,
processing .. components, and removing trailing separators. It does
not allocate unless it’s necessary to reformat the path.
Sourcepub fn unix<S: AsRef<Path> + ?Sized>(path: &S) -> Result<&Self>
pub fn unix<S: AsRef<Path> + ?Sized>(path: &S) -> Result<&Self>
Converts a path that is already normalized and uses ‘/’ separators
into a RelPath .
Returns an error if the path is not already in the correct format.
pub fn is_empty(&self) -> bool
pub fn components(&self) -> RelPathComponents<'_> ⓘ
pub fn ancestors(&self) -> RelPathAncestors<'_> ⓘ
pub fn file_name(&self) -> Option<&str>
pub fn file_stem(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
pub fn parent(&self) -> Option<&Self>
pub fn starts_with(&self, other: &Self) -> bool
pub fn ends_with(&self, other: &Self) -> bool
pub fn strip_prefix<'a>(&'a self, other: &Self) -> Result<&'a Self>
pub fn len(&self) -> usize
pub fn last_n_components(&self, count: usize) -> Option<&Self>
pub fn join(&self, other: &Self) -> Arc<Self>
pub fn to_rel_path_buf(&self) -> RelPathBuf
pub fn into_arc(&self) -> Arc<Self>
Sourcepub fn from_proto(path: &str) -> Result<Arc<Self>>
pub fn from_proto(path: &str) -> Result<Arc<Self>>
Load the path from its wire representation.
Sourcepub fn display(&self, style: PathStyle) -> Cow<'_, str>
pub fn display(&self, style: PathStyle) -> Cow<'_, str>
Convert the path into a string with the given path style.
Whenever a path is presented to the user, it should be converted to a string via this method.
Sourcepub fn as_unix_str(&self) -> &str
pub fn as_unix_str(&self) -> &str
Get the internal unix-style representation of the path.
This should not be shown to the user.
Sourcepub fn as_std_path(&self) -> &Path
pub fn as_std_path(&self) -> &Path
Interprets the path as a std::path::Path, suitable for file system calls.
This is guaranteed to be a valid path regardless of the host platform, because
the / is accepted as a path separator on windows.
This should not be shown to the user.
Trait Implementations§
Source§impl AsRef<RelPath> for RelPathBuf
impl AsRef<RelPath> for RelPathBuf
Source§impl Borrow<RelPath> for RelPathBuf
impl Borrow<RelPath> for RelPathBuf
Source§impl PartialOrd for RelPath
impl PartialOrd for RelPath
Source§impl ToOwned for RelPath
impl ToOwned for RelPath
Source§type Owned = RelPathBuf
type Owned = RelPathBuf
Source§fn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
1.63.0 · Source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
impl Eq for RelPath
impl StructuralPartialEq for RelPath
Auto Trait Implementations§
impl Freeze for RelPath
impl RefUnwindSafe for RelPath
impl Send for RelPath
impl !Sized for RelPath
impl Sync for RelPath
impl Unpin for RelPath
impl UnwindSafe for RelPath
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.