D6485: rust-filepatterns: use bytes instead of String
Yuya Nishihara
yuya at tcha.org
Tue Jun 11 19:23:09 EDT 2019
> +pub fn get_path_from_bytes(bytes: &[u8]) -> &Path {
> + let os_str;
> + #[cfg(unix)]
> + {
> + use std::os::unix::ffi::OsStrExt;
> + os_str = std::ffi::OsStr::from_bytes(bytes);
> + }
> + #[cfg(windows)]
> + {
> + use std::os::windows::ffi::OsStrExt;
> + os_str = std::ffi::OsString::from_wide(bytes);
> + }
OsStringExt can't be used on Windows. It expects a UTF-16 slice of `&[u16]`
type, but filename isn't stored in UTF-16 nor UTF-8. It's in ANSI
(or locale-dependent) encoding.
Maybe we'll have to call Win32API directly, or use a wrapper crate around it.
https://docs.microsoft.com/en-us/windows/desktop/Intl/unicode-and-character-set-functions
More information about the Mercurial-devel
mailing list