pub struct SimpleUnc {
pub map_to_drive: bool,
pub skip_dunce: bool,
pub _unused: bool,
}Expand description
Simplifies Win32 File Namespaces paths (the “\\?\” prefix)
for better readability and compatibility.
SimpleUnc::default().canonicalize(path);is a snap-in replacement of fs::canonicalize.
C:\dir | Z:\x (network) | |
|---|---|---|
fs::canonicalize | \\?\C:\dir | \\?\UNC\server\share\x |
SimpleUnc | C:\dir | \\server\share\x |
SimpleUnc with map_to_drive | C:\dir | Z:\x |
Fields§
§map_to_drive: boolMap to the network share drive when possible.
let path = "file.txt";
let unc = SimpleUnc { map_to_drive: true, ..Default::default() };
let canonicalized = unc.canonicalize(path)?;If the file.txt is in a network drive,
the result is Z:\dir\file.txt
instead of \\server\share\dir\file.txt.
The following code tries to preserve the original form of the path.
SimpleUnc {
map_to_drive: !path.as_os_str().as_encoded_bytes().starts_with(br"\\"),
..Default::default()
}.canonicalize(path)?;skip_dunce: boolThe dunce simplification is applied by default.
Set to true to skip it.
_unused: boolIt is highly recommended to always use , ..Default::default().
Otherwise builds fail when new fields are added.
This field is not used in any ways,
but exists to allow using , ..Default::default()
even when all other fields are specified.
Implementations§
Source§impl SimpleUnc
impl SimpleUnc
Sourcepub fn canonicalize(&self, path: impl AsRef<Path>) -> Result<PathBuf>
pub fn canonicalize(&self, path: impl AsRef<Path>) -> Result<PathBuf>
Calls fs::canonicalize and simplify.
On other platforms than Windows,
this is equivalent to fs::canonicalize.