Skip to main content

simplify_verbatim

Function simplify_verbatim 

Source
pub fn simplify_verbatim(path: PathBuf) -> PathBuf
Expand description

Drop the \\?\ verbatim prefix that Windows’ GetFinalPathNameByHandle — and so std::fs::canonicalize — puts in front of every canonical path.

Python’s pathlib.Path.resolve() and os.path.realpath() return the plain C:\dir\file spelling, so the verbatim form is a byte-divergence in every message that prints a resolved path (_StrPath(...) reprs, Include file '...', :diff: headers). It is also a FUNCTIONAL hazard: inside a verbatim path Windows does no normalization at all — / is an ordinary filename character there and .. is not resolved — so a lexically joined \\?\C:\src + sub/inner.rst names nothing.

\\?\UNC\server\share maps back to \\server\share; a path long enough that the prefix is what makes it openable at all keeps it (the 260-character MAX_PATH limit, which the plain spelling is only exempt from with a per-application opt-in this crate does not make). A non-Windows path matches neither shape, so this is the identity function there.