nu_path

Type Alias RelativePathBuf

Source
pub type RelativePathBuf = PathBuf<Relative>;
Expand description

A path buf that is strictly relative.

I.e., this path buf is guaranteed to never be absolute.

RelativePathBufs cannot be easily referenced as a std::path::Path or converted to a std::path::PathBuf 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 easily referenced as a std::path::Path. If you really mean it, you can instead use as_relative_std_path or into_relative_std_path_buf to get the underlying std::path::Path or std::path::PathBuf from a RelativePathBuf. 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 or into_relative_std_path_buf.

§Examples

RelativePathBufs can be created by using try_into_relative on a PathBuf or by using to_path_buf on a RelativePath.

use nu_path::{PathBuf, RelativePath, RelativePathBuf};

let path_buf = PathBuf::from("foo.txt");
let path_buf = path_buf.try_into_relative().unwrap();

let path = RelativePath::try_new("foo.txt").unwrap();
let path_buf2 = path.to_path_buf();

assert_eq!(path_buf, path_buf2);

You can also use RelativePathBuf::try_from or try_into. This supports attempted conversions from Path as well as types in std::path.

use nu_path::{Path, RelativePathBuf};

let path1 = RelativePathBuf::try_from("foo.txt").unwrap();

let path2 = Path::new("foo.txt");
let path2 = RelativePathBuf::try_from(path2).unwrap();

let path3 = std::path::PathBuf::from("foo.txt");
let path3: RelativePathBuf = path3.try_into().unwrap();

assert_eq!(path1, path2);
assert_eq!(path2, path3);

Aliased Type§

struct RelativePathBuf { /* private fields */ }

Trait Implementations§

Source§

impl<T: ?Sized + AsRef<RelativePath>> From<&T> for RelativePathBuf

Source§

fn from(s: &T) -> Self

Converts to this type from the input type.
Source§

impl FromStr for RelativePathBuf

Source§

type Err = TryRelativeError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

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

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> PartialEq<Cow<'a, Path>> for RelativePathBuf

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

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<PathBuf> for RelativePathBuf

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 RelativePathBuf

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> PartialOrd<Cow<'a, Path>> for RelativePathBuf

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

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<PathBuf> for RelativePathBuf

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 TryFrom<&Component<'_>> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&Cow<'_, OsStr>> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&OsStr> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&OsString> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&Path> for RelativePathBuf

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 RelativePathBuf

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<&PathBuf> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&PathBuf> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&String> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<&str> for RelativePathBuf

Source§

type Error = TryRelativeError

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

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

Performs the conversion.
Source§

impl TryFrom<Box<Path>> for RelativePathBuf

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 RelativePathBuf

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 RelativePathBuf

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 RelativePathBuf

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<OsString> for RelativePathBuf

Source§

type Error = OsString

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

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

Performs the conversion.
Source§

impl TryFrom<PathBuf> for RelativePathBuf

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 RelativePathBuf

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<String> for RelativePathBuf

Source§

type Error = String

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

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

Performs the conversion.