[−][src]Trait os_str_bytes::OsStringBytes
A platform agnostic variant of OsStringExt
.
For more information, see the module-level documentation.
Required methods
fn from_bytes<TString>(string: TString) -> Result<Self, EncodingError> where
TString: AsRef<[u8]>,
TString: AsRef<[u8]>,
Copies a byte slice into an equivalent platform-native string.
It is always better to use from_cow
when the bytes may be owned.
Errors
See documentation for EncodingError
.
Examples
use std::env; use std::ffi::OsString; use os_str_bytes::OsStrBytes; use os_str_bytes::OsStringBytes; let os_string = env::current_exe()?; let os_bytes = os_string.to_bytes(); assert_eq!(os_string, OsString::from_bytes(os_bytes).unwrap());
fn from_vec(string: Vec<u8>) -> Result<Self, EncodingError>
Converts a byte vector into an equivalent platform-native string.
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_vec(); assert_eq!(os_string, OsString::from_vec(os_bytes).unwrap());
#[must_use]fn into_vec(self) -> Vec<u8>
Converts a platform-native string into an equivalent byte vector.
Examples
use std::env; use os_str_bytes::OsStringBytes; let os_string = env::current_exe()?; println!("{:?}", os_string.into_vec());
Provided methods
fn from_cow(string: Cow<'_, [u8]>) -> Result<Self, EncodingError>
A convenience method to call either from_bytes
or from_vec
,
depending on whether a byte sequence is owned.
This method can be useful in coordination with
OsStrBytes::to_bytes
, since the parameter type matches that
method's return type.
Errors
See documentation for EncodingError
.
Examples
use std::env; use std::ffi::OsString; use os_str_bytes::OsStrBytes; use os_str_bytes::OsStringBytes; let os_string = env::current_exe()?; let os_bytes = os_string.to_bytes(); assert_eq!(os_string, OsString::from_cow(os_bytes).unwrap());
Implementations on Foreign Types
impl OsStringBytes for OsString
[src]
fn from_bytes<TString>(string: TString) -> Result<Self, EncodingError> where
TString: AsRef<[u8]>,
[src]
TString: AsRef<[u8]>,
fn from_vec(string: Vec<u8>) -> Result<Self, EncodingError>
[src]
fn into_vec(self) -> Vec<u8>
[src]
impl OsStringBytes for PathBuf
[src]
fn from_bytes<TString>(string: TString) -> Result<Self, EncodingError> where
TString: AsRef<[u8]>,
[src]
TString: AsRef<[u8]>,