[−][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.
Errors
See documentation for EncodingError.
Examples
use std::ffi::OsString; use os_str_bytes::OsStringBytes; let string = b"foo\xED\xA0\xBDbar"; assert_eq!(string.len(), OsString::from_bytes(string)?.len());
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::ffi::OsString; use os_str_bytes::OsStringBytes; let string = b"foo\xED\xA0\xBDbar".to_vec(); assert_eq!(string.len(), OsString::from_vec(string)?.len());
#[must_use]fn into_vec(self) -> Vec<u8>
Converts a platform-native string into an equivalent byte vector.
Examples
use std::ffi::OsString; use os_str_bytes::OsStringBytes; let string = b"foo\xED\xA0\xBDbar".to_vec(); let os_string = OsString::from_vec(string.clone())?; assert_eq!(string, 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::ffi::OsStr; use std::ffi::OsString; use os_str_bytes::OsStrBytes; use os_str_bytes::OsStringBytes; let os_string = OsStr::from_bytes(b"foo\xED\xA0\xBDbar")?; assert_eq!(os_string, OsString::from_cow(os_string.to_bytes())?);
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]>,