pub struct Path<'a> { /* private fields */ }Expand description
Path provides a copy-on-write-style path that is built around UTF8 strings.
Implementations§
Source§impl<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub fn into_owned(self) -> Path<'static>
pub fn into_owned(self) -> Path<'static>
Convert the path into an owned path.
Sourcepub fn as_std_path(&self) -> &Path
pub fn as_std_path(&self) -> &Path
Convert the path to a std::path::Path.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Convert the path to a string, losslessly because this type is always UTF-8.
Sourcepub fn to_path_buf(&self) -> PathBuf
pub fn to_path_buf(&self) -> PathBuf
Convert the path to a std::path::PathBuf.
Sourcepub fn is_symlink(&self) -> Result<bool>
pub fn is_symlink(&self) -> Result<bool>
Is the path a symbolic link?
Sourcepub fn basename(&self) -> Path<'_>
pub fn basename(&self) -> Path<'_>
Compute the basename of the path. This is guaranteed to be a non-empty path component (falling back to “.” for paths that end with “/”).
Sourcepub fn dirname(&self) -> Path<'_>
pub fn dirname(&self) -> Path<'_>
Compute the dirname of the path. This is guaranteed to be a non-empty path component (falling back to “.” or “/” for single-component paths).
Sourcepub fn try_exists(&self) -> Result<bool>
pub fn try_exists(&self) -> Result<bool>
Return whether the path exists, preserving I/O errors.
Sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Query the filesystem for metadata, following symbolic links.
Sourcepub fn symlink_metadata(&self) -> Result<Metadata>
pub fn symlink_metadata(&self) -> Result<Metadata>
Query the filesystem for metadata without following symbolic links.
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Return an iterator over the entries in this directory.
Sourcepub fn has_root(&self) -> bool
pub fn has_root(&self) -> bool
True if the path begins with some number of slashes, other than the POSIX-exception of //.
Sourcepub fn has_app_defined(&self) -> bool
pub fn has_app_defined(&self) -> bool
True if the path begins with //, but not ///.
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
True if the path is absolute.
Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
True if the path is relative.
Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
True if the path contains no “.” components; and, is absolute and has no “..” components, or is relative and has all “..” components at the start.
Sourcepub fn join<'b, 'c>(&self, with: impl Into<Path<'b>>) -> Path<'c>where
'a: 'c,
'b: 'c,
pub fn join<'b, 'c>(&self, with: impl Into<Path<'b>>) -> Path<'c>where
'a: 'c,
'b: 'c,
Join to this path another path. Follows standard path rules where if the joined-with path is absolute, the first path is discarded.
Sourcepub fn strip_prefix<'b>(&self, prefix: impl Into<Path<'b>>) -> Option<Path<'_>>
pub fn strip_prefix<'b>(&self, prefix: impl Into<Path<'b>>) -> Option<Path<'_>>
Strip a prefix from the path. The prefix and path are allowed to be non-normal and will have “.” components dropped from consideration.
Sourcepub fn starts_with<'b>(&self, base: impl Into<Path<'b>>) -> bool
pub fn starts_with<'b>(&self, base: impl Into<Path<'b>>) -> bool
True if the path starts with the provided base path.
Sourcepub fn ends_with<'b>(&self, child: impl Into<Path<'b>>) -> bool
pub fn ends_with<'b>(&self, child: impl Into<Path<'b>>) -> bool
True if the path ends with the provided child path.
Sourcepub fn ancestors(&self) -> impl Iterator<Item = Path<'static>> + '_
pub fn ancestors(&self) -> impl Iterator<Item = Path<'static>> + '_
Iterate over the path and its parents.
Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
Return the final path component, if it is a normal file name.
Sourcepub fn file_prefix(&self) -> Option<&str>
pub fn file_prefix(&self) -> Option<&str>
Return the file name without its first extension.
Sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Return the final file extension without the leading dot.
Sourcepub fn with_file_name(&self, file_name: impl AsRef<str>) -> Path<'static>
pub fn with_file_name(&self, file_name: impl AsRef<str>) -> Path<'static>
Create a path like this one, but with its file name replaced.
Sourcepub fn with_extension(&self, extension: impl AsRef<str>) -> Path<'static>
pub fn with_extension(&self, extension: impl AsRef<str>) -> Path<'static>
Create a path like this one, but with its extension replaced.
Sourcepub fn with_added_extension(&self, extension: impl AsRef<str>) -> Path<'static>
pub fn with_added_extension(&self, extension: impl AsRef<str>) -> Path<'static>
Create a path like this one, but with an extension added.
Sourcepub fn split(&self) -> (Path<'_>, Path<'_>)
pub fn split(&self) -> (Path<'_>, Path<'_>)
Split the path into basename and dirname components.
Sourcepub fn components(&self) -> impl Iterator<Item = Component<'_>>
pub fn components(&self) -> impl Iterator<Item = Component<'_>>
Return an iterator over the path components. A path with a basename of “.” will always end with Component::CurDir.
Sourcepub fn cwd() -> Option<Path<'a>>
pub fn cwd() -> Option<Path<'a>>
Return the current working directory, if it can be fetched and converted to unicode without error.
Sourcepub fn canonicalize(&self) -> Result<Path<'static>, Error>
pub fn canonicalize(&self) -> Result<Path<'static>, Error>
Return the canonicalized path with all intermediate components normalized and symbolic links resolved.