Type Alias nu_path::AbsolutePath
source · pub type AbsolutePath = Path<Absolute>;Expand description
A path that is strictly absolute.
I.e., this path is guaranteed to never be relative.
§Examples
AbsolutePaths can be created by using try_absolute on a Path
or by using try_new.
use nu_path::{AbsolutePath, Path};
let path1 = Path::new("/foo").try_absolute().unwrap();
let path2 = AbsolutePath::try_new("/foo").unwrap();
assert_eq!(path1, path2);You can also use AbsolutePath::try_from or try_into.
This supports attempted conversions from Path as well as types in std::path.
use nu_path::{AbsolutePath, Path};
let path1 = Path::new("/foo");
let path1: &AbsolutePath = path1.try_into().unwrap();
let path2 = std::path::Path::new("/foo");
let path2: &AbsolutePath = path2.try_into().unwrap();
assert_eq!(path1, path2)Aliased Type§
struct AbsolutePath { /* private fields */ }Implementations§
source§impl AbsolutePath
impl AbsolutePath
sourcepub fn canonicalize(&self) -> Result<CanonicalPathBuf>
pub fn canonicalize(&self) -> Result<CanonicalPathBuf>
Returns the canonical, absolute form of the path with all intermediate components normalized and symbolic links resolved.
On Windows, this will also simplify to a winuser path.
This is an alias to std::fs::canonicalize.
§Examples
use nu_path::{AbsolutePath, PathBuf};
let path = AbsolutePath::try_new("/foo/test/../test/bar.rs").unwrap();
assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs"));sourcepub fn read_link(&self) -> Result<AbsolutePathBuf>
pub fn read_link(&self) -> Result<AbsolutePathBuf>
Reads a symbolic link, returning the file that the link points to.
This is an alias to std::fs::read_link.
§Examples
use nu_path::AbsolutePath;
let path = AbsolutePath::try_new("/laputa/sky_castle.rs").unwrap();
let path_link = path.read_link().expect("read_link call failed");sourcepub fn try_exists(&self) -> Result<bool>
pub fn try_exists(&self) -> Result<bool>
Returns Ok(true) if the path points at an existing entity.
This function will traverse symbolic links to query information about the destination file.
In case of broken symbolic links this will return Ok(false).
Path::exists only checks whether or not a path was both found and readable.
By contrast, try_exists will return Ok(true) or Ok(false),
respectively, if the path was verified to exist or not exist.
If its existence can neither be confirmed nor denied, it will propagate an Err instead.
This can be the case if e.g. listing permission is denied on one of the parent directories.
Note that while this avoids some pitfalls of the exists method,
it still can not prevent time-of-check to time-of-use (TOCTOU) bugs.
You should only use it in scenarios where those bugs are not an issue.
§Examples
use nu_path::AbsolutePath;
let path = AbsolutePath::try_new("/does_not_exist").unwrap();
assert!(!path.try_exists().unwrap());
let path = AbsolutePath::try_new("/root/secret_file.txt").unwrap();
assert!(path.try_exists().is_err());sourcepub fn is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
Returns true if the path exists on disk and is pointing at a symbolic link.
This function will not traverse symbolic links. In case of a broken symbolic link this will also return true.
If you cannot access the directory containing the file, e.g., because of a permission error, this will return false.
§Examples
use nu_path::AbsolutePath;
use std::os::unix::fs::symlink;
let link_path = AbsolutePath::try_new("/link").unwrap();
symlink("/origin_does_not_exist/", link_path).unwrap();
assert_eq!(link_path.is_symlink(), true);
assert_eq!(link_path.exists(), false);sourcepub fn symlink_metadata(&self) -> Result<Metadata>
pub fn symlink_metadata(&self) -> Result<Metadata>
Queries the metadata about a file without following symlinks.
This is an alias to std::fs::symlink_metadata.
§Examples
use nu_path::AbsolutePath;
let path = AbsolutePath::try_new("/Minas/tirith").unwrap();
let metadata = path.symlink_metadata().expect("symlink_metadata call failed");
println!("{:?}", metadata.file_type());Trait Implementations§
source§impl From<Box<Path<Canonical>>> for Box<AbsolutePath>
impl From<Box<Path<Canonical>>> for Box<AbsolutePath>
source§fn from(path: Box<CanonicalPath>) -> Self
fn from(path: Box<CanonicalPath>) -> Self
source§impl From<Cow<'_, Path<Canonical>>> for Box<AbsolutePath>
impl From<Cow<'_, Path<Canonical>>> for Box<AbsolutePath>
source§fn from(cow: Cow<'_, CanonicalPath>) -> Self
fn from(cow: Cow<'_, CanonicalPath>) -> Self
source§impl From<PathBuf<Canonical>> for Box<AbsolutePath>
impl From<PathBuf<Canonical>> for Box<AbsolutePath>
source§fn from(buf: CanonicalPathBuf) -> Self
fn from(buf: CanonicalPathBuf) -> Self
source§impl<'a> PartialEq<&'a Path<Canonical>> for AbsolutePath
impl<'a> PartialEq<&'a Path<Canonical>> for AbsolutePath
source§fn eq(&self, other: &&'a CanonicalPath) -> bool
fn eq(&self, other: &&'a CanonicalPath) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<&'a Path> for AbsolutePath
impl<'a> PartialEq<&'a Path> for AbsolutePath
source§impl<'a, 'b> PartialEq<Cow<'a, Path<Canonical>>> for &'b AbsolutePath
impl<'a, 'b> PartialEq<Cow<'a, Path<Canonical>>> for &'b AbsolutePath
source§impl<'a> PartialEq<Cow<'a, Path<Canonical>>> for AbsolutePath
impl<'a> PartialEq<Cow<'a, Path<Canonical>>> for AbsolutePath
source§impl<'a, 'b> PartialEq<Cow<'a, Path>> for &'b AbsolutePath
impl<'a, 'b> PartialEq<Cow<'a, Path>> for &'b AbsolutePath
source§impl<'a> PartialEq<Cow<'a, Path>> for AbsolutePath
impl<'a> PartialEq<Cow<'a, Path>> for AbsolutePath
source§impl<'a> PartialEq<Path<Canonical>> for &'a AbsolutePath
impl<'a> PartialEq<Path<Canonical>> for &'a AbsolutePath
source§fn eq(&self, other: &CanonicalPath) -> bool
fn eq(&self, other: &CanonicalPath) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<Path<Canonical>> for AbsolutePath
impl PartialEq<Path<Canonical>> for AbsolutePath
source§fn eq(&self, other: &CanonicalPath) -> bool
fn eq(&self, other: &CanonicalPath) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<Path> for &'a AbsolutePath
impl<'a> PartialEq<Path> for &'a AbsolutePath
source§impl PartialEq<Path> for AbsolutePath
impl PartialEq<Path> for AbsolutePath
source§impl<'a> PartialEq<PathBuf<Canonical>> for &'a AbsolutePath
impl<'a> PartialEq<PathBuf<Canonical>> for &'a AbsolutePath
source§fn eq(&self, other: &CanonicalPathBuf) -> bool
fn eq(&self, other: &CanonicalPathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<PathBuf<Canonical>> for AbsolutePath
impl PartialEq<PathBuf<Canonical>> for AbsolutePath
source§fn eq(&self, other: &CanonicalPathBuf) -> bool
fn eq(&self, other: &CanonicalPathBuf) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<PathBuf> for &'a AbsolutePath
impl<'a> PartialEq<PathBuf> for &'a AbsolutePath
source§impl PartialEq<PathBuf> for AbsolutePath
impl PartialEq<PathBuf> for AbsolutePath
source§impl<'a> PartialOrd<&'a Path<Canonical>> for AbsolutePath
impl<'a> PartialOrd<&'a Path<Canonical>> for AbsolutePath
source§fn partial_cmp(&self, other: &&'a CanonicalPath) -> Option<Ordering>
fn partial_cmp(&self, other: &&'a CanonicalPath) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<&'a Path> for AbsolutePath
impl<'a> PartialOrd<&'a Path> for AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<Cow<'a, Path<Canonical>>> for &'b AbsolutePath
impl<'a, 'b> PartialOrd<Cow<'a, Path<Canonical>>> for &'b AbsolutePath
source§fn partial_cmp(&self, other: &Cow<'a, CanonicalPath>) -> Option<Ordering>
fn partial_cmp(&self, other: &Cow<'a, CanonicalPath>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<Cow<'a, Path<Canonical>>> for AbsolutePath
impl<'a> PartialOrd<Cow<'a, Path<Canonical>>> for AbsolutePath
source§fn partial_cmp(&self, other: &Cow<'a, CanonicalPath>) -> Option<Ordering>
fn partial_cmp(&self, other: &Cow<'a, CanonicalPath>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<Cow<'a, Path>> for &'b AbsolutePath
impl<'a, 'b> PartialOrd<Cow<'a, Path>> for &'b AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<Cow<'a, Path>> for AbsolutePath
impl<'a> PartialOrd<Cow<'a, Path>> for AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<Path<Canonical>> for &'a AbsolutePath
impl<'a> PartialOrd<Path<Canonical>> for &'a AbsolutePath
source§fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<Path<Canonical>> for AbsolutePath
impl PartialOrd<Path<Canonical>> for AbsolutePath
source§fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<Path> for &'a AbsolutePath
impl<'a> PartialOrd<Path> for &'a AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<Path> for AbsolutePath
impl PartialOrd<Path> for AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<PathBuf<Canonical>> for &'a AbsolutePath
impl<'a> PartialOrd<PathBuf<Canonical>> for &'a AbsolutePath
source§fn partial_cmp(&self, other: &CanonicalPathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &CanonicalPathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<PathBuf<Canonical>> for AbsolutePath
impl PartialOrd<PathBuf<Canonical>> for AbsolutePath
source§fn partial_cmp(&self, other: &CanonicalPathBuf) -> Option<Ordering>
fn partial_cmp(&self, other: &CanonicalPathBuf) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<PathBuf> for &'a AbsolutePath
impl<'a> PartialOrd<PathBuf> for &'a AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<PathBuf> for AbsolutePath
impl PartialOrd<PathBuf> for AbsolutePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more