Trait os_str_bytes::OsStringBytes

source ·
pub trait OsStringBytes: Sealed + Sized {
    // Required methods
    fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>;
    fn into_raw_vec(self) -> Vec<u8>;
}
Expand description

A platform agnostic variant of OsStringExt.

For more information, see the module-level documentation.

Required Methods§

source

fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>

Converts a byte vector into an equivalent platform-native string.

Provided byte strings should always be valid for the unspecified encoding used by this crate.

§Errors

See documentation for EncodingError.

§Examples
use std::env;
use std::ffi::OsString;

use os_str_bytes::OsStringBytes;

let os_string = env::current_exe()?;
let os_bytes = os_string.clone().into_raw_vec();
assert_eq!(os_string, OsString::from_raw_vec(os_bytes).unwrap());
source

fn into_raw_vec(self) -> Vec<u8>

Converts a platform-native string into an equivalent byte vector.

The returned byte string will use an unspecified encoding.

§Examples
use std::env;

use os_str_bytes::OsStringBytes;

let os_string = env::current_exe()?;
println!("{:?}", os_string.into_raw_vec());

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl OsStringBytes for OsString

source§

impl OsStringBytes for PathBuf

Implementors§