Function absolute
fn absolute<P: AsRef<Path>>(path: P) -> io::Result<PathBuf>
Makes the path absolute without accessing the filesystem.
If the path is relative, the current directory is used as the base directory.
All intermediate components will be resolved according to platform-specific
rules, but unlike [canonicalize][crate::fs::canonicalize], this does not
resolve symlinks and may succeed even if the path does not exist.
If the path is empty or getting the
[current directory][crate::env::current_dir] fails, then an error will be
returned.
Platform-specific behavior
On POSIX platforms, the path is resolved using POSIX semantics,
except that it stops short of resolving symlinks. This means it will keep ..
components and trailing separators.
On Windows, for verbatim paths, this will simply return the path as given. For other
paths, this is currently equivalent to calling
GetFullPathNameW.
On Cygwin, this is currently equivalent to calling cygwin_conv_path
with mode CCP_WIN_A_TO_POSIX, and then being processed like other POSIX platforms.
If a Windows path is given, it will be converted to an absolute POSIX path without
keeping ...
Note that these may change in the future.
Errors
This function may return an error in the following situations:
- If
pathis syntactically invalid; in particular, if it is empty. - If getting the [current directory][crate::env::current_dir] fails.
Examples
POSIX paths
#
#
#
Windows paths
#
#
#
Note that this may change in the future.