Skip to main content

Path

Struct Path 

Source
pub struct Path<'a>(/* private fields */);
Expand description

A borrowed path in a target’s syntax.

Implementations§

Source§

impl<'a> Path<'a>

Source

pub fn new(path: &'a (impl AsRef<str> + ?Sized), kind: Kind) -> Self

Creates a path with the given syntax.

Source

pub fn unix(path: &'a (impl AsRef<str> + ?Sized)) -> Self

Creates a path with Unix syntax.

Source

pub fn windows(path: &'a (impl AsRef<str> + ?Sized)) -> Self

Creates a path with Windows syntax.

Source

pub fn kind(&self) -> Kind

Returns this path’s syntax.

Source

pub fn as_str(&self) -> &'a str

Returns the path text.

Source

pub fn to_path_buf(&self) -> PathBuf

Converts this path into an owned path.

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<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.

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<'a>>

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<Self>

Returns the path without its final component.

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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.

Source

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.

Source

pub fn without_stream(&self) -> PathBuf

Returns this path with any alternate data stream specifier removed.

Source

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

Returns an iterator over the path’s components.

Source

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

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

Source

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

Returns this path with path appended.

Source

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.

Source

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.

Source

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.

Source

pub fn normalize(&self) -> PathBuf

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

This is a purely textual operation: no symlink is resolved and the target is never consulted.

Trait Implementations§

Source§

impl AsRef<str> for Path<'_>

Source§

fn as_ref(&self) -> &str

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

impl<'a> Clone for Path<'a>

Source§

fn clone(&self) -> Path<'a>

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<'a> Copy for Path<'a>

Source§

impl<'a> Debug for Path<'a>

Source§

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

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

impl Display for Path<'_>

Source§

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

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

impl<'a> Eq for Path<'a>

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<'a> Hash for Path<'a>

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<'a> Ord for Path<'a>

Source§

fn cmp(&self, other: &Path<'a>) -> 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<'a> PartialEq for Path<'a>

Source§

fn eq(&self, other: &Path<'a>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<'a> PartialOrd for Path<'a>

Source§

fn partial_cmp(&self, other: &Path<'a>) -> 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<'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> 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> 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> 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.