pub struct PathAbs(_);
Expand description
An absolute (not necessarily canonicalized) path that may or may not exist.
Implementations§
source§impl PathAbs
impl PathAbs
sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<PathAbs>
pub fn new<P: AsRef<Path>>(path: P) -> Result<PathAbs>
Construct an absolute path from an arbitrary (absolute or relative) one.
This is different from canonicalize
in that it preserves symlinks
and the destination may or may not exist.
This function will:
- Resolve relative paths against the current working directory.
- Strip any
.
components (/a/./c
->/a/c
) - Resolve
..
semantically (not using the file system). So,a/b/c/../d => a/b/d
will always be true regardless of symlinks. If you want symlinks correctly resolved, usecanonicalize()
instead.
On windows, this will sometimes call
canonicalize()
on the first component to guarantee it is the correct canonicalized prefix. For paths starting with root it also has to get thecurrent_dir
On linux, the only syscall this will make is to get the
current_dir
for relative paths.
Examples
use path_abs::{PathAbs, PathInfo};
let lib = PathAbs::new("src/lib.rs")?;
assert_eq!(lib.is_absolute(), true);
sourcepub fn new_unchecked<P: Into<Arc<PathBuf>>>(path: P) -> PathAbs
pub fn new_unchecked<P: Into<Arc<PathBuf>>>(path: P) -> PathAbs
Create a PathAbs unchecked.
This is mostly used for constructing during tests, or if the path was previously validated.
This is effectively the same as a Arc<PathBuf>
.
Note: This is memory safe, so is not marked
unsafe
. However, it could cause panics in some methods if the path was not properly validated.
Trait Implementations§
source§impl Ord for PathAbs
impl Ord for PathAbs
source§impl PartialEq<PathAbs> for PathAbs
impl PartialEq<PathAbs> for PathAbs
source§impl PartialOrd<PathAbs> for PathAbs
impl PartialOrd<PathAbs> for PathAbs
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 PathMut for PathAbs
impl PathMut for PathAbs
source§fn append<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
fn append<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
path
to this path. Read moresource§fn truncate_to_root(&mut self)
fn truncate_to_root(&mut self)
fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)
fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool
source§impl PathOps for PathAbs
impl PathOps for PathAbs
type Output = PathAbs
source§fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>
fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>
source§fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output
fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output
std::path::Path::join
with all of its gotchas and pitfalls,, except
returns a more relevant type. Read more