Struct path_abs::PathAbs [] [src]

pub struct PathAbs(_);

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

Methods

impl PathAbs
[src]

[src]

Instantiate a new PathAbs. The path must exist or io::Error will be returned.

Examples

use path_abs::PathAbs;

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

[src]

Resolve the PathAbs as a PathFile. Return an error if it is not a file.

[src]

Resolve the PathAbs as a PathDir. Return an error if it is not a directory.

[src]

Get the parent directory of this path as a PathDir.

This does not make aditional syscalls, as the parent by definition must be a directory and exist.

Examples

use path_abs::{PathDir, PathFile};

let lib = PathFile::new("src/lib.rs")?;
let src = lib.parent_dir().unwrap();
assert_eq!(PathDir::new("src")?, src);

[src]

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

[src]

For constructing mocked paths during tests. This is effectively the same as a PathBuf.

This is NOT checked for validity so the file may or may not actually exist and will NOT be, in any way, an absolute or canonicalized path.

Examples

use path_abs::PathAbs;

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

let lib_mocked = PathAbs::mock("src/lib.rs");

// in this case, the mocked file exists
assert!(lib_mocked.exists());

// However, it is NOT equivalent to `lib`
assert_ne!(lib, lib_mocked);

// this file doesn't exist at all
let dne = PathAbs::mock("src/dne.rs");
assert!(!dne.exists());

Methods from Deref<Target = PathArc>

[src]

Creates an owned PathBuf with path adjoined to self.

This function is identical to std::path::PathBuf::join except it returns PathArc instead of PathBuf

[src]

Creates an owned PathArc like self but with the given file name.

This function is identical to std::path::PathBuf::with_file_name except it returns PathArc instead of PathBuf

[src]

Creates an owned PathArc like self but with the given extension.

This function is identical to std::path::PathBuf::with_extension except it returns PathArc instead of PathBuf

[src]

Queries the file system to get information about a file, directory, etc.

This function will traverse symbolic links to query information about the destination file.

This function is identical to std::path::Path::metadata except it has error messages which include the action and the path

Queries the metadata about a file without following symlinks.

This function is identical to std::path::Path::symlink_metadata except it has error messages which include the action and the path

[src]

Returns the canonical form of the path with all intermediate components normalized and symbolic links resolved.

This function is identical to std::path::Path::canonicalize except:

  • It returns a PathAbs object
  • It has error messages which include the action and the path

Reads a symbolic link, returning the file that the link points to.

This function is identical to std::path::Path::read_link except:

  • It returns a PathArc object instead of PathBuf
  • It has error messages which include the action and the path

[src]

Returns an iterator over the entries within a directory.

This function is a shortcut to PathDir::list. It is slightly different than std::path::Path::read_dir.

[src]

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

[src]

Convert the path to an absolute one, this is different from canonicalize in that it preserves symlinks and the destination may or may not exist.

This function will:

  • Use current_dir to resolve relative paths.
  • 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.

Trait Implementations

impl Clone for PathAbs
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for PathAbs
[src]

impl Hash for PathAbs
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq for PathAbs
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl PartialOrd for PathAbs
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for PathAbs
[src]

[src]

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

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Debug for PathAbs
[src]

[src]

Formats the value using the given formatter. Read more

impl AsRef<PathArc> for PathAbs
[src]

[src]

Performs the conversion.

impl AsRef<Path> for PathAbs
[src]

[src]

Performs the conversion.

impl AsRef<PathBuf> for PathAbs
[src]

[src]

Performs the conversion.

impl Borrow<PathArc> for PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl Borrow<Path> for PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl Borrow<PathBuf> for PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<PathArc> for &'a PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<Path> for &'a PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<PathBuf> for &'a PathAbs
[src]

[src]

Immutably borrows from an owned value. Read more

impl Deref for PathAbs
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl Into<PathArc> for PathAbs
[src]

[src]

Performs the conversion.

impl AsRef<PathAbs> for PathDir
[src]

[src]

Performs the conversion.

impl Borrow<PathAbs> for PathDir
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<PathAbs> for &'a PathDir
[src]

[src]

Immutably borrows from an owned value. Read more

impl Into<PathAbs> for PathDir
[src]

[src]

Downgrades the PathDir into a PathAbs

Examples

use std::path::PathBuf;
use path_abs::{PathDir, PathAbs};

let dir = PathDir::new("src")?;
let abs: PathAbs = dir.into();

impl AsRef<PathAbs> for PathFile
[src]

[src]

Performs the conversion.

impl Borrow<PathAbs> for PathFile
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<PathAbs> for &'a PathFile
[src]

[src]

Immutably borrows from an owned value. Read more

impl Into<PathAbs> for PathFile
[src]

[src]

Downgrades the PathFile into a PathAbs

Examples

use std::path::PathBuf;
use path_abs::{PathFile, PathAbs};

let file = PathFile::new("src/lib.rs")?;
let abs: PathAbs = file.clone().into();

impl Serialize for PathAbs
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for PathAbs
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more

impl AsRef<PathAbs> for PathType
[src]

[src]

Performs the conversion.

impl Borrow<PathAbs> for PathType
[src]

[src]

Immutably borrows from an owned value. Read more

impl<'a> Borrow<PathAbs> for &'a PathType
[src]

[src]

Immutably borrows from an owned value. Read more

impl Into<PathAbs> for PathType
[src]

[src]

Downgrades the PathType into a PathAbs

Examples

use std::path::PathBuf;
use path_abs::{PathType, PathAbs};

let ty = PathType::new("src/lib.rs")?;
let abs: PathAbs = ty.into();

Auto Trait Implementations

impl Send for PathAbs

impl Sync for PathAbs