pub struct PathBuf(/* private fields */);Expand description
An owned path in a target’s syntax.
Implementations§
Source§impl PathBuf
impl PathBuf
Sourcepub fn from_windows(path: impl AsRef<str>) -> Self
pub fn from_windows(path: impl AsRef<str>) -> Self
Creates a path with Windows syntax.
Sourcepub fn from_native(path: PathBuf) -> Result<Self>
pub fn from_native(path: PathBuf) -> Result<Self>
Sourcepub fn set_file_name(&mut self, file_name: impl AsRef<str>)
pub fn set_file_name(&mut self, file_name: impl AsRef<str>)
Replaces the final component, keeping any alternate data stream suffix.
Sourcepub fn set_extension(&mut self, extension: impl AsRef<str>) -> bool
pub fn set_extension(&mut self, extension: impl AsRef<str>) -> bool
Replaces the extension of the final component, keeping any alternate data stream suffix, and returns whether the path had a final component to modify.
Sourcepub fn set_stream(&mut self, spec: Option<StreamSpec<'_>>)
pub fn set_stream(&mut self, spec: Option<StreamSpec<'_>>)
Replaces the alternate data stream specifier of the final component.
Has no effect on a Unix path.
Source§impl PathBuf
Methods shared with Path, forwarded for convenience.
impl PathBuf
Methods shared with Path, forwarded for convenience.
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 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<'_>>
pub fn strip_prefix(&self, base: impl AsRef<str>) -> Result<Path<'_>>
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<&str>
pub fn file_name(&self) -> Option<&str>
Returns the final component, excluding any alternate data stream suffix.
Sourcepub fn file_name_raw(&self) -> Option<&str>
pub fn file_name_raw(&self) -> Option<&str>
Returns the final component exactly as it is spelled, including any alternate data stream suffix.
Sourcepub fn file_stem(&self) -> Option<&str>
pub fn file_stem(&self) -> Option<&str>
Returns the final component without its extension or its alternate data stream suffix.
Sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Returns the extension of the final component, ignoring any alternate data stream suffix.
Sourcepub fn stream(&self) -> Result<Option<StreamSpec<'_>>>
pub fn stream(&self) -> Result<Option<StreamSpec<'_>>>
Sourcepub fn without_stream(&self) -> Self
pub fn without_stream(&self) -> Self
Returns this path with any alternate data stream specifier removed.
Sourcepub fn components(&self) -> Components<'_> ⓘ
pub fn components(&self) -> Components<'_> ⓘ
Returns an iterator over the path’s components.
Sourcepub fn with_file_name(&self, file_name: impl AsRef<str>) -> Self
pub fn with_file_name(&self, file_name: impl AsRef<str>) -> Self
Returns this path with its final component replaced, keeping any alternate data stream suffix.
Sourcepub fn with_extension(&self, extension: impl AsRef<str>) -> Self
pub fn with_extension(&self, extension: impl AsRef<str>) -> Self
Returns this path with the extension of its final component replaced, keeping any alternate data stream suffix.
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Returns this path with . components removed and .. components
resolved lexically.
Sourcepub fn windows_prefix(&self) -> Option<WindowsPrefix<'_>>
pub fn windows_prefix(&self) -> Option<WindowsPrefix<'_>>
Returns the Windows prefix, if this is a prefixed Windows path.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PathBuf
impl<'de> Deserialize<'de> for PathBuf
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for PathBuf
Source§impl Ord for PathBuf
impl Ord for PathBuf
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 PartialOrd for PathBuf
impl PartialOrd for PathBuf
impl StructuralPartialEq for PathBuf
Auto Trait Implementations§
impl Freeze for PathBuf
impl RefUnwindSafe for PathBuf
impl Send for PathBuf
impl Sync for PathBuf
impl Unpin for PathBuf
impl UnsafeUnpin for PathBuf
impl UnwindSafe for PathBuf
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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