stable-osstring-encoding 1.0.0

A stable way to convert OsString and OsStr to and from raw data.
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented1 out of 7 items with examples
  • Size
  • Source code size: 14.69 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 531.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • What42Pizza/rust-stable-osstring-encoding
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • What42Pizza

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 std::ffi::OsString;
# use stable_osstring_encoding::*;
let my_string = OsString::from("My String");
let stable_string: Vec<_> = my_string.into_stable_encoding();
// send stable_string to another program
let my_string = OsString::from_stable_encoding(stable_string);

Provided methods:

// note: `StableOsString` is just an alias for `Vec<u8>` or `Vec<u16>` (depending on the platform)
OsStr::to_stable_encoding(&self) -> StableOsString
OsString::to_stable_encoding(&self) -> StableOsString
OsString::into_stable_encoding(self) -> StableOsString
OsString::from_stable_encoding(encoded: Into<Cow<[EncodingWidth]>>) -> OsString