pub fn wsl_to_windows(wsl_path: &str) -> Result<String, Error>Expand description
Convert a WSL path to a Windows path.
The input path needs to be absolute. Path are normalized during conversion.
§Errors
If the path is not absolute, the method returns an Error::RelativePath. Paths not starting
with with /mnt/<driveletter> will lead to an Error::InvalidPrefix.
§Examples
use wslpath_rs::{wsl_to_windows, Error};
// Absolute paths are supported
assert_eq!(wsl_to_windows("/mnt/c/Windows").unwrap(), "C:\\Windows");
assert_eq!(wsl_to_windows("/mnt/d/foo/../bar/./baz.txt").unwrap(), "D:\\bar\\baz.txt");
assert_eq!(wsl_to_windows("/mnt/c/Program Files (x86)/Foo/bar.txt").unwrap(), "C:\\Program Files (x86)\\Foo\\bar.txt");
// Absolute paths not starting with `/mnt/<driveletter>` are not supported
assert_eq!(wsl_to_windows("/etc/fstab").unwrap_err(), Error::InvalidPrefix);
assert_eq!(wsl_to_windows("/mnt/my_custom_mount/foo/bar.txt").unwrap_err(), Error::InvalidPrefix);
// Relative paths are not supported
assert_eq!(wsl_to_windows("Program Files (x86)/Foo/bar.txt").unwrap_err(), Error::RelativePath);
assert_eq!(wsl_to_windows("../foo/bar.txt").unwrap_err(), Error::RelativePath);