os_str_bytes

Trait OsStrBytes

Source
pub trait OsStrBytes: Sealed + ToOwned {
    // Required methods
    fn assert_from_raw_bytes<'a, S>(string: S) -> Cow<'a, Self>
       where S: Into<Cow<'a, [u8]>>;
    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]>;
}
👎Deprecated: enable the ‘conversions’ feature
Expand description

A platform agnostic variant of OsStrExt.

For more information, see the module-level documentation.

Required Methods§

Source

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

👎Deprecated: enable the ‘conversions’ feature

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

§Panics

Panics if the string is not valid for the unspecified encoding used by this crate.

§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::assert_from_raw_bytes(os_bytes));
Source

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

👎Deprecated: use assert_from_raw_bytes instead, or enable the ‘checked_conversions’ feature

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

assert_from_raw_bytes should almost always be used instead. For more information, see EncodingError.

§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]>

👎Deprecated: enable the ‘conversions’ feature

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

The returned string will use an unspecified encoding.

§Examples
use std::ffi::OsStr;

use os_str_bytes::OsStrBytes;

let string = "foobar";
let os_string = OsStr::new(string);
assert_eq!(string.as_bytes(), &*os_string.to_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 OsStrBytes for OsStr

Source§

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

👎Deprecated: enable the ‘conversions’ feature
Source§

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

👎Deprecated: use assert_from_raw_bytes instead, or enable the ‘checked_conversions’ feature
Source§

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

👎Deprecated: enable the ‘conversions’ feature
Source§

impl OsStrBytes for Path

Source§

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

👎Deprecated: enable the ‘conversions’ feature
Source§

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

👎Deprecated: use assert_from_raw_bytes instead, or enable the ‘checked_conversions’ feature
Source§

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

👎Deprecated: enable the ‘conversions’ feature

Implementors§