Rust Stable OsString Encoding
This was made for one very specific reason: the encoding of OsStr::as_encoded_bytes()'s output might change based on the Rust compiler version the code is built with (according to this comment). If you want the the guarantee that the encoded data's encoding will never change depending on the compiler version you're using, this crate provides methods which convert OsStr and OsString to and from a Vec<u8> or Vec<u16> (depending on the platform). This is made possible by the platform-specific OsStrExt and OsStringExt traits, which give and take data that does have an encoding which the standard library promises will not change.
Important caveats:
- This is not meant for sending data from one platform to another (e.g. from a windows program to a linux program).
- This currently only supports Windows and Unix (Linux and MacOs), but other platforms should be easy to implement if needed.
Example:
# use OsString;
# use *;
let my_string = from;
let stable_string: = my_string.into_stable_encoding;
// send stable_string to another program
let my_string = from_stable_encoding;
Provided methods:
// note: `StableOsString` is just an alias for `Vec<u8>` or `Vec<u16>` (depending on the platform)
to_stable_encoding