Skip to main content

PathBuf

Struct PathBuf 

Source
pub struct PathBuf(/* private fields */);
Expand description

An owned path in a target’s syntax.

Implementations§

Source§

impl PathBuf

Source

pub fn new(path: impl AsRef<str>, kind: Kind) -> Self

Creates a path with the given syntax.

Source

pub fn from_unix(path: impl AsRef<str>) -> Self

Creates a path with Unix syntax.

Source

pub fn from_windows(path: impl AsRef<str>) -> Self

Creates a path with Windows syntax.

Source

pub fn empty(kind: Kind) -> Self

Creates an empty path with the given syntax.

Source

pub fn from_native(path: PathBuf) -> Result<Self>

Creates a path from a native host path.

§Errors

Fails if the path is not valid UTF-8.

Source

pub fn to_path(&self) -> Path<'_>

Borrows this path.

Source

pub fn push(&mut self, path: impl AsRef<str>)

Appends path.

Source

pub fn pop(&mut self) -> bool

Removes the final component, returning whether one was removed.

Source

pub fn set_file_name(&mut self, file_name: impl AsRef<str>)

Replaces the final component, keeping any alternate data stream suffix.

Source

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.

Source

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.

Source

pub fn kind(&self) -> Kind

Returns this path’s syntax.

Source

pub fn as_str(&self) -> &str

Returns the path text.

Source

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.

Source

pub fn to_kind(&self, kind: Kind) -> Result<Self>

Converts this path into the given syntax.

§Errors

See Path::to_kind.

Source

pub fn is_absolute(&self) -> bool

Returns whether the path is absolute.

Source

pub fn is_relative(&self) -> bool

Returns whether the path is relative.

Source

pub fn has_root(&self) -> bool

Returns whether the path has a root component.

Source

pub fn starts_with(&self, base: impl AsRef<str>) -> bool

Returns whether the path begins with base.

Source

pub fn ends_with(&self, child: impl AsRef<str>) -> bool

Returns whether the path ends with child.

Source

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.

Source

pub fn parent(&self) -> Option<Path<'_>>

Returns the path without its final component.

Source

pub fn file_name(&self) -> Option<&str>

Returns the final component, excluding any alternate data stream suffix.

Source

pub fn file_name_raw(&self) -> Option<&str>

Returns the final component exactly as it is spelled, including any alternate data stream suffix.

Source

pub fn file_stem(&self) -> Option<&str>

Returns the final component without its extension or its alternate data stream suffix.

Source

pub fn extension(&self) -> Option<&str>

Returns the extension of the final component, ignoring any alternate data stream suffix.

Source

pub fn stream(&self) -> Result<Option<StreamSpec<'_>>>

Returns the alternate data stream specified by the final component.

§Errors

See Path::stream.

Source

pub fn without_stream(&self) -> Self

Returns this path with any alternate data stream specifier removed.

Source

pub fn components(&self) -> Components<'_>

Returns an iterator over the path’s components.

Source

pub fn join(&self, path: impl AsRef<str>) -> Self

Returns this path with path appended.

Source

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.

Source

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.

Source

pub fn normalize(&self) -> Self

Returns this path with . components removed and .. components resolved lexically.

Source

pub fn windows_prefix(&self) -> Option<WindowsPrefix<'_>>

Returns the Windows prefix, if this is a prefixed Windows path.

Trait Implementations§

Source§

impl AsRef<str> for PathBuf

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for PathBuf

Source§

fn clone(&self) -> PathBuf

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathBuf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PathBuf

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PathBuf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PathBuf

Source§

impl<'a> From<&'a PathBuf> for Path<'a>

Source§

fn from(path: &'a PathBuf) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Path<'a>> for PathBuf

Source§

fn from(path: Path<'a>) -> Self

Converts to this type from the input type.
Source§

impl Hash for PathBuf

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for PathBuf

Source§

fn cmp(&self, other: &PathBuf) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for PathBuf

Source§

fn eq(&self, other: &PathBuf) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for PathBuf

Source§

fn partial_cmp(&self, other: &PathBuf) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for PathBuf

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PathBuf

Source§

impl TryFrom<PathBuf> for PathBuf

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(path: PathBuf) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for PathBuf

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(path: PathBuf) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.