[−][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 a new equivalent platform-native string.
Examples
use os_str_bytes::OsStringBytes; let string = b"foo\xED\xA0\xBDbar"; assert_eq!(string.len(), OsString::from_bytes(string)?.len());
#[must_use]unsafe fn from_bytes_unchecked<TString>(string: TString) -> Self where
TString: AsRef<[u8]>,
TString: AsRef<[u8]>,
The unsafe equivalent of from_bytes
.
More information is given in that method's documentation.
Safety
This method is unsafe for the same reason as
OsStrBytes::from_bytes_unchecked
.
fn from_vec(string: Vec<u8>) -> Result<Self, EncodingError>
Converts a byte vector into an equivalent platform-native string.
Whenever possible, the conversion will be performed without copying.
Examples
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]unsafe fn from_vec_unchecked(string: Vec<u8>) -> Self
The unsafe equivalent of from_vec
.
More information is given in that method's documentation.
Safety
This method is unsafe for the same reason as
OsStrBytes::from_bytes_unchecked
.
#[must_use]fn into_vec(self) -> Vec<u8>
Converts the internal byte representation into a byte vector.
Whenever possible, the conversion will be performed without copying.
Examples
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());
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]>,
unsafe fn from_bytes_unchecked<TString>(string: TString) -> Self where
TString: AsRef<[u8]>,
[src]
TString: AsRef<[u8]>,