Type Alias nu_path::RelativePath
source · pub type RelativePath = Path<Relative>;Expand description
A path that is strictly relative.
I.e., this path is guaranteed to never be absolute.
RelativePaths cannot be easily converted into a std::path::Path by design.
Other Nushell crates need to account for the emulated current working directory
before passing a path to functions in std or other third party crates.
You can join a RelativePath onto an AbsolutePath or a CanonicalPath.
This will return an AbsolutePathBuf which can be referenced as a std::path::Path.
If you really mean it, you can use as_relative_std_path
to get the underlying std::path::Path from a RelativePath.
But this may cause third-party code to use std::env::current_dir to resolve
the path which is almost always incorrect behavior. Extra care is needed to ensure that this
is not the case after using as_relative_std_path.
§Examples
RelativePaths can be created by using try_relative
on a Path, by using try_new, or by using
strip_prefix on a Path of any form.
use nu_path::{Path, RelativePath};
let path1 = Path::new("foo.txt");
let path1 = path1.try_relative().unwrap();
let path2 = RelativePath::try_new("foo.txt").unwrap();
let path3 = Path::new("/prefix/foo.txt").strip_prefix("/prefix").unwrap();
assert_eq!(path1, path2);
assert_eq!(path2, path3);You can also use RelativePath::try_from or try_into.
This supports attempted conversions from Path as well as types in std::path.
use nu_path::{Path, RelativePath};
let path1 = Path::new("foo.txt");
let path1: &RelativePath = path1.try_into().unwrap();
let path2 = std::path::Path::new("foo.txt");
let path2: &RelativePath = path2.try_into().unwrap();
assert_eq!(path1, path2)Aliased Type§
struct RelativePath { /* private fields */ }Trait Implementations§
source§impl<'a> PartialEq<&'a Path> for RelativePath
impl<'a> PartialEq<&'a Path> for RelativePath
source§impl<'a, 'b> PartialEq<Cow<'a, Path>> for &'b RelativePath
impl<'a, 'b> PartialEq<Cow<'a, Path>> for &'b RelativePath
source§impl<'a> PartialEq<Cow<'a, Path>> for RelativePath
impl<'a> PartialEq<Cow<'a, Path>> for RelativePath
source§impl<'a> PartialEq<Path> for &'a RelativePath
impl<'a> PartialEq<Path> for &'a RelativePath
source§impl PartialEq<Path> for RelativePath
impl PartialEq<Path> for RelativePath
source§impl<'a> PartialEq<PathBuf> for &'a RelativePath
impl<'a> PartialEq<PathBuf> for &'a RelativePath
source§impl PartialEq<PathBuf> for RelativePath
impl PartialEq<PathBuf> for RelativePath
source§impl<'a> PartialOrd<&'a Path> for RelativePath
impl<'a> PartialOrd<&'a Path> for RelativePath
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 RelativePath
impl<'a, 'b> PartialOrd<Cow<'a, Path>> for &'b RelativePath
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 RelativePath
impl<'a> PartialOrd<Cow<'a, Path>> for RelativePath
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 RelativePath
impl<'a> PartialOrd<Path> for &'a RelativePath
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 RelativePath
impl PartialOrd<Path> for RelativePath
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 RelativePath
impl<'a> PartialOrd<PathBuf> for &'a RelativePath
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 RelativePath
impl PartialOrd<PathBuf> for RelativePath
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