pub struct SimpleUnc {
pub disallow_long: bool,
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§
§disallow_long: boolWhen set to true,
the simplification is disabled
if the result is a “long path” (longer than 260 characters).
Long paths may not be supported by some programs and APIs.
In such cases, the Win32 File Namespaces (the “\\?\” prefix)
may be able to work around the limitation.
On the other hand,
other programs such as PowerShell v7 can’t handle the “\\?\” prefix,
but it can handle long paths.
map_to_drive: boolMap to network share drive names 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.