pub trait RawOsStrCow<'a>: Sealed {
// Required methods
fn from_os_str(string: Cow<'a, OsStr>) -> Self;
fn into_os_str(self) -> Cow<'a, OsStr>;
fn into_raw_bytes(self) -> Cow<'a, [u8]>;
}
Expand description
Extensions to Cow<RawOsStr>
for additional conversions.
Required Methods§
Sourcefn from_os_str(string: Cow<'a, OsStr>) -> Self
fn from_os_str(string: Cow<'a, OsStr>) -> Self
Converts a platform-native string back to this representation.
§Nightly Notes
This method does not require copying or encoding conversion.
§Examples
use std::borrow::Cow;
use std::env;
use os_str_bytes::RawOsStr;
use os_str_bytes::RawOsStrCow;
let os_string = Cow::Owned(env::current_exe()?.into_os_string());
println!("{:?}", Cow::from_os_str(os_string));
Sourcefn into_os_str(self) -> Cow<'a, OsStr>
fn into_os_str(self) -> Cow<'a, OsStr>
Converts this representation back to a platform-native string.
§Nightly Notes
This method does not require copying or encoding conversion.
§Examples
use std::env;
use os_str_bytes::RawOsStr;
use os_str_bytes::RawOsStrCow;
let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
assert_eq!(os_string, raw.into_os_str());
Sourcefn into_raw_bytes(self) -> Cow<'a, [u8]>
👎Deprecated: enable the ‘conversions’ feature
fn into_raw_bytes(self) -> Cow<'a, [u8]>
Returns the byte string stored by this container.
The returned string will use an unspecified encoding.
§Examples
use std::borrow::Cow;
use os_str_bytes::RawOsStr;
use os_str_bytes::RawOsStrCow;
let string = "foobar";
let raw = Cow::Borrowed(RawOsStr::from_str(string));
assert_eq!(string.as_bytes(), &*raw.into_raw_bytes());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a> RawOsStrCow<'a> for Cow<'a, RawOsStr>
impl<'a> RawOsStrCow<'a> for Cow<'a, RawOsStr>
fn from_os_str(string: Cow<'a, OsStr>) -> Self
fn into_os_str(self) -> Cow<'a, OsStr>
Source§fn into_raw_bytes(self) -> Cow<'a, [u8]>
fn into_raw_bytes(self) -> Cow<'a, [u8]>
👎Deprecated: enable the ‘conversions’ feature