Skip to main content

Path

Struct Path 

Source
#[repr(transparent)]
pub struct Path(Path);
Expand description

A borrowed native path with lexical operations only.

Filesystem-query methods are deliberately absent. Use this crate’s operation modules to inspect or mutate the host filesystem.

Tuple Fields§

§0: Path

Implementations§

Source§

impl Path

Source

pub fn new<S>(path: &S) -> &Self
where S: AsRef<OsStr> + ?Sized,

Borrow a native path without allocating.

Source

pub fn as_os_str(&self) -> &OsStr

Return the underlying operating-system string.

Source

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

Return this path as UTF-8 when every byte is valid UTF-8.

Source

pub fn display(&self) -> Display<'_>

Return a display adapter that replaces invalid UTF-8 lossily.

Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Return this path as a potentially lossy string.

Source

pub fn to_path_buf(&self) -> PathBuf

Allocate an owned copy.

Source

pub fn join<S>(&self, path: S) -> PathBuf
where S: AsRef<NativePath>,

Join a lexical path segment.

Source

pub fn parent(&self) -> Option<&Self>

Return the parent path.

Source

pub fn ancestors(&self) -> Ancestors<'_>

Iterate over this path and each lexical parent.

Source

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

Return the final component.

Source

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

Return the final component without its last extension.

Source

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

Return the final extension.

Source

pub fn with_file_name<S>(&self, file_name: S) -> PathBuf
where S: AsRef<OsStr>,

Return a path with a different final component.

Source

pub fn with_extension<S>(&self, extension: S) -> PathBuf
where S: AsRef<OsStr>,

Return a path with a different extension.

Source

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

Iterate over normalized lexical components.

Source

pub fn starts_with<S>(&self, base: S) -> bool
where S: AsRef<NativePath>,

Report whether this path begins with base on component boundaries.

Source

pub fn strip_prefix<S>(&self, base: S) -> Result<&Self, StripPrefixError>
where S: AsRef<NativePath>,

Remove a component-aligned prefix.

§Errors

Returns an error when base is not a lexical prefix of this path.

Source

pub fn is_absolute(&self) -> bool

Report whether the path is absolute for the current platform.

Source

pub fn is_empty(&self) -> bool

Report whether the path has no components.

Trait Implementations§

Source§

impl AsRef<OsStr> for Path

Source§

fn as_ref(&self) -> &OsStr

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

impl AsRef<Path> for Path

Source§

fn as_ref(&self) -> &NativePath

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

impl AsRef<Path> for Path

Source§

fn as_ref(&self) -> &Path

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

impl AsRef<Path> for PathBuf

Source§

fn as_ref(&self) -> &Path

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

impl Borrow<Path> for PathBuf

Source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
Source§

impl Debug for Path

Source§

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

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

impl From<&Path> for PathBuf

Source§

fn from(path: &Path) -> Self

Converts to this type from the input type.
Source§

impl Hash for Path

Source§

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

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

impl Ord for Path

Source§

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

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for Path

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Path

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 RefCast for Path

Source§

type From = Path

Source§

fn ref_cast(_from: &Self::From) -> &Self

Source§

fn ref_cast_mut(_from: &mut Self::From) -> &mut Self

Source§

impl Eq for Path

Source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl !Sized for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnsafeUnpin for Path

§

impl UnwindSafe for Path

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