Type Alias nu_path::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
impl<T: ?Sized + AsRef<RelativePath>> From<&T> for RelativePathBuf
source§impl FromStr for RelativePathBuf
impl FromStr for RelativePathBuf
source§impl<'a> PartialEq<&'a Path> for RelativePathBuf
impl<'a> PartialEq<&'a Path> for RelativePathBuf
source§impl<'a> PartialEq<Cow<'a, Path>> for RelativePathBuf
impl<'a> PartialEq<Cow<'a, Path>> for RelativePathBuf
source§impl PartialEq<Path> for RelativePathBuf
impl PartialEq<Path> for RelativePathBuf
source§impl PartialEq<PathBuf> for RelativePathBuf
impl PartialEq<PathBuf> for RelativePathBuf
source§impl<'a> PartialOrd<&'a Path> for RelativePathBuf
impl<'a> PartialOrd<&'a Path> for RelativePathBuf
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 RelativePathBuf
impl<'a> PartialOrd<Cow<'a, Path>> for RelativePathBuf
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 RelativePathBuf
impl PartialOrd<Path> for RelativePathBuf
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 RelativePathBuf
impl PartialOrd<PathBuf> for RelativePathBuf
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