pub fn os_string_to_bytes(
os_string: OsString,
) -> Result<Vec<u8>, ConvertBytesError>
Expand description
Convert a platform-specific OsString
to a byte vec.
Unsupported platforms fallback to converting through String
.
§Examples
let platform_string: OsString = OsString::from("/etc/passwd");
assert_eq!(
os_string_to_bytes(platform_string),
Ok(b"/etc/passwd".to_vec())
);
§Errors
On unix-like platforms, this function is infallible.
On Windows, if the given byte slice does not contain valid UTF-8, an error is returned.