nu_path

Type Alias 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 AsRef<Path> for Box<RelativePath>

Source§

fn as_ref(&self) -> &Path

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

impl<'a> PartialEq<&'a Path> for RelativePath

Source§

fn eq(&self, other: &&'a 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<'a, 'b> PartialEq<Cow<'a, Path>> for &'b RelativePath

Source§

fn eq(&self, other: &Cow<'a, 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<'a> PartialEq<Cow<'a, Path>> for RelativePath

Source§

fn eq(&self, other: &Cow<'a, 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<'a> PartialEq<Path> for &'a RelativePath

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 PartialEq<Path> for RelativePath

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<'a> PartialEq<PathBuf> for &'a RelativePath

Source§

fn eq(&self, other: &PathBuf) -> 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 PartialEq<PathBuf> for RelativePath

Source§

fn eq(&self, other: &PathBuf) -> 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<'a> PartialOrd<&'a Path> for RelativePath

Source§

fn partial_cmp(&self, other: &&'a 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<'a, 'b> PartialOrd<Cow<'a, Path>> for &'b RelativePath

Source§

fn partial_cmp(&self, other: &Cow<'a, 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<'a> PartialOrd<Cow<'a, Path>> for RelativePath

Source§

fn partial_cmp(&self, other: &Cow<'a, 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<'a> PartialOrd<Path> for &'a RelativePath

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 PartialOrd<Path> for RelativePath

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<'a> PartialOrd<PathBuf> for &'a RelativePath

Source§

fn partial_cmp(&self, other: &PathBuf) -> 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 PartialOrd<PathBuf> for RelativePath

Source§

fn partial_cmp(&self, other: &PathBuf) -> 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<'a> TryFrom<&'a Component<'_>> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(component: &'a Component<'_>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Components<'_>> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(components: &'a Components<'_>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Cow<'_, OsStr>> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(s: &'a Cow<'_, OsStr>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Iter<'_>> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(iter: &'a Iter<'_>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a OsStr> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(s: &'a OsStr) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a OsString> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(s: &'a OsString) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Path> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(path: &'a Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Path> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(path: &'a Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Path> for Box<RelativePath>

Source§

type Error = TryRelativeError

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

fn try_from(path: &Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Path> for Box<RelativePath>

Source§

type Error = TryRelativeError

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

fn try_from(path: &Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a PathBuf> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(buf: &'a PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a PathBuf> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(buf: &'a PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a String> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(s: &'a String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a str> for &'a RelativePath

Source§

type Error = TryRelativeError

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

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Box<Path>> for Box<RelativePath>

Source§

type Error = Box<Path>

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

fn try_from(path: Box<Path>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Box<Path>> for Box<RelativePath>

Source§

type Error = Box<Path>

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

fn try_from(path: Box<Path>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<Cow<'a, Path>> for Box<RelativePath>

Source§

type Error = Cow<'a, Path>

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

fn try_from(path: Cow<'a, Path>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<Cow<'a, Path>> for Box<RelativePath>

Source§

type Error = Cow<'a, Path>

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

fn try_from(path: Cow<'a, Path>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for Box<RelativePath>

Source§

type Error = PathBuf

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

fn try_from(buf: PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for Box<RelativePath>

Source§

type Error = PathBuf

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

fn try_from(buf: PathBuf) -> Result<Self, Self::Error>

Performs the conversion.