Trait os_str_bytes::OsStrBytes

source ·
pub trait OsStrBytes: Sealed + ToOwned {
    // Required methods
    fn from_raw_bytes<'a, S>(string: S) -> Result<Cow<'a, Self>, EncodingError>
       where S: Into<Cow<'a, [u8]>>;
    fn to_raw_bytes(&self) -> Cow<'_, [u8]>;
}
Expand description

A platform agnostic variant of OsStrExt.

For more information, see the module-level documentation.

Required Methods§

source

fn from_raw_bytes<'a, S>(string: S) -> Result<Cow<'a, Self>, EncodingError>
where S: Into<Cow<'a, [u8]>>,

Converts a byte slice into an equivalent platform-native string.

Provided byte strings should always be valid for the unspecified encoding used by this crate.

§Errors

See documentation for EncodingError.

§Examples
use std::env;
use std::ffi::OsStr;

use os_str_bytes::OsStrBytes;

let os_string = env::current_exe()?;
let os_bytes = os_string.to_raw_bytes();
assert_eq!(os_string, OsStr::from_raw_bytes(os_bytes).unwrap());
source

fn to_raw_bytes(&self) -> Cow<'_, [u8]>

Converts a platform-native string into an equivalent byte slice.

The returned bytes string will use an unspecified encoding.

§Examples
use std::env;

use os_str_bytes::OsStrBytes;

let os_string = env::current_exe()?;
println!("{:?}", os_string.to_raw_bytes());

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl OsStrBytes for OsStr

source§

fn from_raw_bytes<'a, S>(string: S) -> Result<Cow<'a, Self>, EncodingError>
where S: Into<Cow<'a, [u8]>>,

source§

fn to_raw_bytes(&self) -> Cow<'_, [u8]>

source§

impl OsStrBytes for Path

source§

fn from_raw_bytes<'a, S>(string: S) -> Result<Cow<'a, Self>, EncodingError>
where S: Into<Cow<'a, [u8]>>,

source§

fn to_raw_bytes(&self) -> Cow<'_, [u8]>

Implementors§