path_abs

Struct PathAbs

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

An absolute (not necessarily canonicalized) path that may or may not exist.

Implementations§

Source§

impl PathAbs

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<PathAbs>

Construct an absolute path from an arbitrary (absolute or relative) one.

This is different from canonicalize in that it preserves symlinks and the destination may or may not exist.

This function will:

  • Resolve relative paths against the current working directory.
  • Strip any . components (/a/./c -> /a/c)
  • Resolve .. semantically (not using the file system). So, a/b/c/../d => a/b/d will always be true regardless of symlinks. If you want symlinks correctly resolved, use canonicalize() instead.

On windows, this will sometimes call canonicalize() on the first component to guarantee it is the correct canonicalized prefix. For paths starting with root it also has to get the current_dir

On linux, the only syscall this will make is to get the current_dir for relative paths.

§Examples
use path_abs::{PathAbs, PathInfo};

let lib = PathAbs::new("src/lib.rs")?;

assert_eq!(lib.is_absolute(), true);
Source

pub fn new_unchecked<P: Into<Arc<PathBuf>>>(path: P) -> PathAbs

Create a PathAbs unchecked.

This is mostly used for constructing during tests, or if the path was previously validated. This is effectively the same as a Arc<PathBuf>.

Note: This is memory safe, so is not marked unsafe. However, it could cause panics in some methods if the path was not properly validated.

Source

pub fn as_path(&self) -> &Path

Return a reference to a basic std::path::Path

Trait Implementations§

Source§

impl AsRef<OsStr> for PathAbs

Source§

fn as_ref(&self) -> &OsStr

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

impl AsRef<Path> for PathAbs

Source§

fn as_ref(&self) -> &Path

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

impl AsRef<PathAbs> for PathDir

Source§

fn as_ref(&self) -> &PathAbs

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

impl AsRef<PathAbs> for PathFile

Source§

fn as_ref(&self) -> &PathAbs

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

impl AsRef<PathAbs> for PathType

Source§

fn as_ref(&self) -> &PathAbs

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

impl AsRef<PathBuf> for PathAbs

Source§

fn as_ref(&self) -> &PathBuf

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

impl<'a> Borrow<Path> for &'a PathAbs

Source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
Source§

impl Borrow<Path> for PathAbs

Source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
Source§

impl<'a> Borrow<PathAbs> for &'a PathDir

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl<'a> Borrow<PathAbs> for &'a PathFile

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl<'a> Borrow<PathAbs> for &'a PathType

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl Borrow<PathAbs> for PathDir

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl Borrow<PathAbs> for PathFile

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl Borrow<PathAbs> for PathType

Source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
Source§

impl<'a> Borrow<PathBuf> for &'a PathAbs

Source§

fn borrow(&self) -> &PathBuf

Immutably borrows from an owned value. Read more
Source§

impl Borrow<PathBuf> for PathAbs

Source§

fn borrow(&self) -> &PathBuf

Immutably borrows from an owned value. Read more
Source§

impl Clone for PathAbs

Source§

fn clone(&self) -> PathAbs

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PathAbs

Source§

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

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

impl<'de> Deserialize<'de> for PathAbs

Source§

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

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

impl From<PathAbs> for Arc<PathBuf>

Source§

fn from(path: PathAbs) -> Arc<PathBuf>

Converts to this type from the input type.
Source§

impl From<PathAbs> for PathBuf

Source§

fn from(path: PathAbs) -> PathBuf

Converts to this type from the input type.
Source§

impl From<PathDir> for PathAbs

Source§

fn from(path: PathDir) -> PathAbs

Converts to this type from the input type.
Source§

impl From<PathFile> for PathAbs

Source§

fn from(path: PathFile) -> PathAbs

Converts to this type from the input type.
Source§

impl From<PathType> for PathAbs

Source§

fn from(path: PathType) -> PathAbs

Converts to this type from the input type.
Source§

impl Hash for PathAbs

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 PathAbs

Source§

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

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

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for PathAbs

Source§

fn eq(&self, other: &PathAbs) -> 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 PathAbs

Source§

fn partial_cmp(&self, other: &PathAbs) -> 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 PathMut for PathAbs

Source§

fn append<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Appends path to this path. Read more
Source§

fn pop_up(&mut self) -> Result<()>

Go “up” one directory. Read more
Source§

fn truncate_to_root(&mut self)

Removes all components after the root, if any. Read more
Source§

fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)

Source§

fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool

Source§

impl PathOps for PathAbs

Source§

type Output = PathAbs

Source§

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

Returns a new value representing the concatenation of two paths. Read more
Source§

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

An exact replica of std::path::Path::join with all of its gotchas and pitfalls,, except returns a more relevant type. Read more
Source§

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

Creates a new path object like self but with the given file name. Read more
Source§

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

Creates a new path object like self but with the given extension. Read more
Source§

impl Serialize for PathAbs

Source§

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

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

impl Eq for PathAbs

Source§

impl StructuralPartialEq for PathAbs

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> PathInfo for T
where T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,

Source§

fn as_path(&self) -> &Path

Source§

fn to_arc_pathbuf(&self) -> Arc<PathBuf>

Source§

fn as_os_str(&self) -> &OsStr

Source§

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

Source§

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

Source§

fn is_absolute(&self) -> bool

Source§

fn is_relative(&self) -> bool

Source§

fn has_root(&self) -> bool

Source§

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

Source§

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

Source§

fn strip_prefix<P>(&self, base: P) -> Result<&Path, StripPrefixError>
where P: AsRef<Path>,

Source§

fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool

Source§

fn ends_with<P: AsRef<Path>>(&self, base: P) -> bool

Source§

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

Source§

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

Source§

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

Source§

fn iter(&self) -> Iter<'_>

Source§

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

Source§

fn metadata(&self) -> Result<Metadata>

Queries the file system to get information about a file, directory, etc. Read more
Queries the metadata about a file without following symlinks. Read more
Source§

fn exists(&self) -> bool

Source§

fn is_file(&self) -> bool

Source§

fn is_dir(&self) -> bool

Reads a symbolic link, returning the path that the link points to. Read more
Source§

fn canonicalize(&self) -> Result<PathAbs>

Returns the canonical, absolute form of the path with all intermediate components normalized and symbolic links resolved. Read more
Source§

fn parent(&self) -> Result<&Path>

Returns the path without its final component, if there is one. 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> ToStfu8 for T
where T: Borrow<PathBuf>,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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