pub struct Path<'a>(/* private fields */);Expand description
A borrowed path in a target’s syntax.
Implementations§
Source§impl<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub fn new(path: &'a (impl AsRef<str> + ?Sized), kind: Kind) -> Self
pub fn new(path: &'a (impl AsRef<str> + ?Sized), kind: Kind) -> Self
Creates a path with the given syntax.
Sourcepub fn windows(path: &'a (impl AsRef<str> + ?Sized)) -> Self
pub fn windows(path: &'a (impl AsRef<str> + ?Sized)) -> Self
Creates a path with Windows syntax.
Sourcepub fn to_path_buf(&self) -> PathBuf
pub fn to_path_buf(&self) -> PathBuf
Converts this path into an owned path.
Sourcepub fn to_native(&self) -> Result<PathBuf>
pub fn to_native(&self) -> Result<PathBuf>
Converts this path into a native host path.
§Errors
Fails if this path’s syntax is not the host’s syntax.
Sourcepub fn to_kind(&self, kind: Kind) -> Result<PathBuf>
pub fn to_kind(&self, kind: Kind) -> Result<PathBuf>
Converts this path into the given syntax.
Returns the path unchanged when it already uses kind.
§Errors
Only relative, unrooted paths carrying no alternate data stream specifier can be converted between syntaxes.
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Returns whether the path is absolute.
Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Returns whether the path is relative.
Sourcepub fn starts_with(&self, base: impl AsRef<str>) -> bool
pub fn starts_with(&self, base: impl AsRef<str>) -> bool
Returns whether the path begins with base.
Sourcepub fn ends_with(&self, child: impl AsRef<str>) -> bool
pub fn ends_with(&self, child: impl AsRef<str>) -> bool
Returns whether the path ends with child.
Sourcepub fn strip_prefix(&self, base: impl AsRef<str>) -> Result<Path<'a>>
pub fn strip_prefix(&self, base: impl AsRef<str>) -> Result<Path<'a>>
Returns the path with base removed from its front.
§Errors
Fails if the path does not begin with base.
Sourcepub fn file_name(&self) -> Option<&'a str>
pub fn file_name(&self) -> Option<&'a str>
Returns the final component, excluding any alternate data stream suffix.
Sourcepub fn file_name_raw(&self) -> Option<&'a str>
pub fn file_name_raw(&self) -> Option<&'a str>
Returns the final component exactly as it is spelled, including any alternate data stream suffix.
Sourcepub fn file_stem(&self) -> Option<&'a str>
pub fn file_stem(&self) -> Option<&'a str>
Returns the final component without its extension or its alternate data stream suffix.
Sourcepub fn extension(&self) -> Option<&'a str>
pub fn extension(&self) -> Option<&'a str>
Returns the extension of the final component, ignoring any alternate data stream suffix.
Sourcepub fn stream(&self) -> Result<Option<StreamSpec<'a>>>
pub fn stream(&self) -> Result<Option<StreamSpec<'a>>>
Returns the alternate data stream specified by the final component.
Always None for a Unix path.
§Errors
Fails if the final component carries a suffix that does not follow the
name:stream[:$TYPE] grammar.
Sourcepub fn with_stream(&self, spec: Option<StreamSpec<'_>>) -> PathBuf
pub fn with_stream(&self, spec: Option<StreamSpec<'_>>) -> PathBuf
Returns this path with its alternate data stream specifier replaced.
Has no effect on a Unix path.
Sourcepub fn without_stream(&self) -> PathBuf
pub fn without_stream(&self) -> PathBuf
Returns this path with any alternate data stream specifier removed.
Sourcepub fn components(&self) -> Components<'a> ⓘ
pub fn components(&self) -> Components<'a> ⓘ
Returns an iterator over the path’s components.
Sourcepub fn windows_prefix(&self) -> Option<WindowsPrefix<'a>>
pub fn windows_prefix(&self) -> Option<WindowsPrefix<'a>>
Returns the Windows prefix, if this is a prefixed Windows path.
Sourcepub fn with_file_name(&self, file_name: impl AsRef<str>) -> PathBuf
pub fn with_file_name(&self, file_name: impl AsRef<str>) -> PathBuf
Returns this path with its final component replaced, keeping any alternate data stream suffix.
Sourcepub fn with_file_name_raw(&self, file_name: impl AsRef<str>) -> PathBuf
pub fn with_file_name_raw(&self, file_name: impl AsRef<str>) -> PathBuf
Returns this path with its final component replaced verbatim, dropping any alternate data stream suffix along with the name it was attached to.
Sourcepub fn with_extension(&self, extension: impl AsRef<str>) -> PathBuf
pub fn with_extension(&self, extension: impl AsRef<str>) -> PathBuf
Returns this path with the extension of its final component replaced, keeping any alternate data stream suffix.
Trait Implementations§
impl<'a> Copy for Path<'a>
impl<'a> Eq for Path<'a>
Source§impl<'a> Ord for Path<'a>
impl<'a> Ord for Path<'a>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a> PartialOrd for Path<'a>
impl<'a> PartialOrd for Path<'a>
impl<'a> StructuralPartialEq for Path<'a>
Auto Trait Implementations§
impl<'a> Freeze for Path<'a>
impl<'a> RefUnwindSafe for Path<'a>
impl<'a> Send for Path<'a>
impl<'a> Sync for Path<'a>
impl<'a> Unpin for Path<'a>
impl<'a> UnsafeUnpin for Path<'a>
impl<'a> UnwindSafe for Path<'a>
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,
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