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.
pub fn new_test<'a>(path: &'a str) -> Cow<'a, Self>
Sourcepub fn from_unix_str<S: AsRef<Path> + ?Sized>(path: &S) -> Result<&Self>
pub fn from_unix_str<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
Sourcepub fn is_descendant_of(&self, ancestor: &Self) -> bool
pub fn is_descendant_of(&self, ancestor: &Self) -> bool
Returns true if this path is a strict descendant of ancestor.
Unlike starts_with, this returns false when self == ancestor
and false when ancestor is empty (since every path trivially
starts with the empty prefix).
pub fn ends_with(&self, other: &Self) -> bool
pub fn strip_prefix<'a>( &'a self, other: &Self, ) -> Result<&'a Self, StripPrefixError>
pub fn len(&self) -> usize
pub fn last_n_components(&self, count: usize) -> Option<&Self>
pub fn join(&self, other: &Self) -> RelPathBuf
pub fn to_rel_path_buf(&self) -> RelPathBuf
pub fn into_arc(&self) -> Arc<Self> ⓘ
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.
Sourcepub fn absolutize(&self, base: impl AsRef<AbsPath>) -> AbsPathBuf
pub fn absolutize(&self, base: impl AsRef<AbsPath>) -> AbsPathBuf
Resolves this relative path against an absolute base path.