Trait os_str_bytes::OsStringBytes
source · pub trait OsStringBytes: Sealed + Sized {
// Required methods
fn assert_from_raw_vec(string: Vec<u8>) -> Self;
fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>;
fn into_raw_vec(self) -> Vec<u8>;
}
👎Deprecated: enable the ‘conversions’ feature
Expand description
A platform agnostic variant of OsStringExt
.
For more information, see the module-level documentation.
Required Methods§
sourcefn assert_from_raw_vec(string: Vec<u8>) -> Self
fn assert_from_raw_vec(string: Vec<u8>) -> Self
👎Deprecated: enable the ‘conversions’ feature
Converts a byte string into an equivalent platform-native string.
§Panics
Panics if the string is not valid for the unspecified encoding used by this crate.
§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::assert_from_raw_vec(os_bytes));
sourcefn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
👎Deprecated: use
assert_from_raw_vec
instead, or enable the ‘checked_conversions’ featureConverts a byte string into an equivalent platform-native string.
assert_from_raw_vec
should almost always be used instead.
For more information, see EncodingError
.
§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(),
);
sourcefn into_raw_vec(self) -> Vec<u8>
fn into_raw_vec(self) -> Vec<u8>
👎Deprecated: enable the ‘conversions’ feature
Converts a platform-native string into an equivalent byte string.
The returned string will use an unspecified encoding.
§Examples
use std::ffi::OsString;
use os_str_bytes::OsStringBytes;
let string = "foobar".to_owned();
let os_string: OsString = string.clone().into();
assert_eq!(string.into_bytes(), os_string.into_raw_vec());
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl OsStringBytes for OsString
impl OsStringBytes for OsString
source§fn assert_from_raw_vec(string: Vec<u8>) -> Self
fn assert_from_raw_vec(string: Vec<u8>) -> Self
👎Deprecated: enable the ‘conversions’ feature
source§fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
👎Deprecated: use
assert_from_raw_vec
instead, or enable the ‘checked_conversions’ featuresource§fn into_raw_vec(self) -> Vec<u8>
fn into_raw_vec(self) -> Vec<u8>
👎Deprecated: enable the ‘conversions’ feature
source§impl OsStringBytes for PathBuf
impl OsStringBytes for PathBuf
source§fn assert_from_raw_vec(string: Vec<u8>) -> Self
fn assert_from_raw_vec(string: Vec<u8>) -> Self
👎Deprecated: enable the ‘conversions’ feature
source§fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
fn from_raw_vec(string: Vec<u8>) -> Result<Self, EncodingError>
👎Deprecated: use
assert_from_raw_vec
instead, or enable the ‘checked_conversions’ featuresource§fn into_raw_vec(self) -> Vec<u8>
fn into_raw_vec(self) -> Vec<u8>
👎Deprecated: enable the ‘conversions’ feature