nu_path Type Alias RelativePathBuf Copy item path 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.
RelativePathBuf
s 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
RelativePathBuf
s 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);
struct RelativePathBuf { }
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string
s
to return a value of this type.
Read more Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.