pub struct PathAbs(/* private fields */);
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<'de> Deserialize<'de> for PathAbs
impl<'de> Deserialize<'de> for PathAbs
Source§fn deserialize<D>(deserializer: D) -> Result<PathAbs, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<PathAbs, D::Error>where
D: Deserializer<'de>,
Source§impl Ord for PathAbs
impl Ord for PathAbs
Source§impl PartialOrd for PathAbs
impl PartialOrd for PathAbs
Source§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 moreimpl Eq for PathAbs
impl StructuralPartialEq for PathAbs
Auto Trait Implementations§
impl Freeze for PathAbs
impl RefUnwindSafe for PathAbs
impl Send for PathAbs
impl Sync for PathAbs
impl Unpin for PathAbs
impl UnwindSafe for PathAbs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)