Struct os_str_bytes::RawOsStr

source ·
pub struct RawOsStr(/* private fields */);
Expand description

A container providing additional functionality for OsStr.

For more information, see OsStrBytesExt.

Implementations§

source§

impl RawOsStr

source

pub fn new<S>(string: &S) -> &Self
where S: AsRef<OsStr> + ?Sized,

Wraps a platform-native string, without copying or encoding conversion.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
println!("{:?}", RawOsStr::new(&os_string));
source

pub fn from_os_str(string: &OsStr) -> &Self

👎Deprecated since 7.0.0: use new instead

Wraps a platform-native string, without copying or encoding conversion.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
println!("{:?}", RawOsStr::from_os_str(&os_string));
source

pub fn from_str(string: &str) -> &Self

👎Deprecated since 7.0.0: use new instead

Wraps a string, without copying or encoding conversion.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::from_str(string);
assert_eq!(string, raw);
source

pub unsafe fn from_encoded_bytes_unchecked(string: &[u8]) -> &Self

Equivalent to OsStr::from_encoded_bytes_unchecked.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
let raw_bytes = raw.as_encoded_bytes();
assert_eq!(raw, unsafe {
    RawOsStr::from_encoded_bytes_unchecked(raw_bytes)
});
source

pub fn assert_cow_from_raw_bytes(string: &[u8]) -> Cow<'_, Self>

Available on crate feature conversions only.

Equivalent to OsStrBytes::assert_from_raw_bytes.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
let raw_bytes = raw.to_raw_bytes();
assert_eq!(raw, &*RawOsStr::assert_cow_from_raw_bytes(&raw_bytes));
source

pub fn cow_from_raw_bytes(string: &[u8]) -> Result<Cow<'_, Self>, EncodingError>

Available on crate feature checked_conversions only.

Equivalent to OsStrBytes::from_raw_bytes.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
let raw_bytes = raw.to_raw_bytes();
assert_eq!(
    Ok(raw),
    RawOsStr::cow_from_raw_bytes(&raw_bytes).as_deref(),
);
source

pub unsafe fn cow_from_raw_bytes_unchecked(string: &[u8]) -> Cow<'_, Self>

👎Deprecated since 6.6.0: use assert_cow_from_raw_bytes or from_encoded_bytes_unchecked instead
Available on crate feature conversions only.

Converts and wraps a byte string.

§Safety

The string must be valid for the unspecified encoding used by this crate.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
let raw_bytes = raw.to_raw_bytes();
assert_eq!(raw, unsafe {
    &*RawOsStr::cow_from_raw_bytes_unchecked(&raw_bytes)
});
source

pub fn as_encoded_bytes(&self) -> &[u8]

Equivalent to OsStr::as_encoded_bytes.

The returned string will not use the unspecified encoding. It can only be passed to methods accepting the internal encoding of OsStr, such as from_encoded_bytes_unchecked.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::new(string);
assert_eq!(string.as_bytes(), raw.as_encoded_bytes());
source

pub fn as_os_str(&self) -> &OsStr

Converts this representation back to a platform-native string, without copying or encoding conversion.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
assert_eq!(os_string, raw.as_os_str());
source

pub fn contains<P>(&self, pat: P) -> bool
where P: Pattern,

Equivalent to OsStrBytesExt::contains.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.contains("oo"));
assert!(!raw.contains("of"));
source

pub fn ends_with<P>(&self, pat: P) -> bool
where P: Pattern,

Equivalent to OsStrBytesExt::ends_with.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.ends_with("bar"));
assert!(!raw.ends_with("foo"));
source

pub fn ends_with_os(&self, pat: &Self) -> bool

Available on crate feature conversions only.

Equivalent to OsStrBytesExt::ends_with_os.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.ends_with_os(RawOsStr::new("bar")));
assert!(!raw.ends_with_os(RawOsStr::new("foo")));
source

pub fn find<P>(&self, pat: P) -> Option<usize>
where P: Pattern,

Equivalent to OsStrBytesExt::find.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!(Some(1), raw.find("o"));
assert_eq!(None, raw.find("of"));
source

pub unsafe fn get_unchecked<I>(&self, index: I) -> &Self
where I: SliceIndex,

Equivalent to OsStrBytesExt::get_unchecked.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!("foo", unsafe { raw.get_unchecked(..3) });
assert_eq!("bar", unsafe { raw.get_unchecked(3..) });
source

pub fn is_empty(&self) -> bool

Equivalent to OsStr::is_empty.

§Examples
use os_str_bytes::RawOsStr;

assert!(RawOsStr::new("").is_empty());
assert!(!RawOsStr::new("foobar").is_empty());
source

pub fn repeat(&self, n: usize) -> RawOsString

Equivalent to OsStrBytesExt::repeat.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foo");
assert_eq!("foofoofoo", raw.repeat(3));
source

pub fn rfind<P>(&self, pat: P) -> Option<usize>
where P: Pattern,

Equivalent to OsStrBytesExt::rfind.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!(Some(2), raw.rfind("o"));
assert_eq!(None, raw.rfind("of"));
source

pub fn rsplit<P>(&self, pat: P) -> RawRSplit<'_, P>
where P: Pattern,

Equivalent to OsStrBytesExt::rsplit.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.rsplit("o").eq(["bar", "", "f"]));
source

pub fn rsplit_once<P>(&self, pat: P) -> Option<(&Self, &Self)>
where P: Pattern,

Equivalent to OsStrBytesExt::rsplit_once.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!(
    Some((RawOsStr::new("fo"), RawOsStr::new("bar"))),
    raw.rsplit_once("o"),
);
assert_eq!(None, raw.rsplit_once("of"));
source

pub fn split<P>(&self, pat: P) -> RawSplit<'_, P>
where P: Pattern,

Equivalent to OsStrBytesExt::split.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.split("o").eq(["f", "", "bar"]));
source

pub fn split_at(&self, mid: usize) -> (&Self, &Self)

Equivalent to OsStrBytesExt::split_at.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!(
    (RawOsStr::new("fo"), RawOsStr::new("obar")),
    raw.split_at(2),
);
source

pub fn split_once<P>(&self, pat: P) -> Option<(&Self, &Self)>
where P: Pattern,

Equivalent to OsStrBytesExt::split_once.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert_eq!(
    Some((RawOsStr::new("f"), RawOsStr::new("obar"))),
    raw.split_once("o"),
);
assert_eq!(None, raw.split_once("of"));
source

pub fn starts_with<P>(&self, pat: P) -> bool
where P: Pattern,

Equivalent to OsStrBytesExt::starts_with.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.starts_with("foo"));
assert!(!raw.starts_with("bar"));
source

pub fn starts_with_os(&self, pat: &Self) -> bool

Available on crate feature conversions only.

Equivalent to OsStrBytesExt::starts_with_os.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("foobar");
assert!(raw.starts_with_os(RawOsStr::new("foo")));
assert!(!raw.starts_with_os(RawOsStr::new("bar")));
source

pub fn strip_prefix<P>(&self, pat: P) -> Option<&Self>
where P: Pattern,

Equivalent to OsStrBytesExt::strip_prefix.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("111foo1bar111");
assert_eq!(Some(RawOsStr::new("11foo1bar111")), raw.strip_prefix("1"));
assert_eq!(None, raw.strip_prefix("o"));
source

pub fn strip_suffix<P>(&self, pat: P) -> Option<&Self>
where P: Pattern,

Equivalent to OsStrBytesExt::strip_suffix.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("111foo1bar111");
assert_eq!(Some(RawOsStr::new("111foo1bar11")), raw.strip_suffix("1"));
assert_eq!(None, raw.strip_suffix("o"));
source

pub fn to_os_str(&self) -> Cow<'_, OsStr>

👎Deprecated since 6.6.0: use as_os_str instead

Converts this representation back to a platform-native string.

When possible, use RawOsStrCow::into_os_str for a more efficient conversion on some platforms.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
assert_eq!(os_string, raw.to_os_str());
source

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

Available on crate feature conversions only.

Equivalent to OsStrBytes::to_raw_bytes.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::new(string);
assert_eq!(string.as_bytes(), &*raw.to_raw_bytes());
source

pub fn to_str(&self) -> Option<&str>

Equivalent to OsStr::to_str.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::new(string);
assert_eq!(Some(string), raw.to_str());
source

pub fn to_str_lossy(&self) -> Cow<'_, str>

Equivalent to OsStr::to_string_lossy.

§Examples
use std::env;

use os_str_bytes::RawOsStr;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsStr::new(&os_string);
println!("{}", raw.to_str_lossy());
source

pub fn trim_end_matches<P>(&self, pat: P) -> &Self
where P: Pattern,

Equivalent to OsStrBytesExt::trim_end_matches.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("111foo1bar111");
assert_eq!("111foo1bar", raw.trim_end_matches("1"));
assert_eq!("111foo1bar111", raw.trim_end_matches("o"));
source

pub fn trim_matches<P>(&self, pat: P) -> &Self
where P: Pattern,

Equivalent to OsStrBytesExt::trim_matches.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("111foo1bar111");
assert_eq!("foo1bar", raw.trim_matches("1"));
assert_eq!("111foo1bar111", raw.trim_matches("o"));
source

pub fn trim_start_matches<P>(&self, pat: P) -> &Self
where P: Pattern,

Equivalent to OsStrBytesExt::trim_start_matches.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::new("111foo1bar111");
assert_eq!("foo1bar111", raw.trim_start_matches("1"));
assert_eq!("111foo1bar111", raw.trim_start_matches("o"));
source

pub fn utf8_chunks(&self) -> Utf8Chunks<'_>

Equivalent to OsStrBytesExt::utf8_chunks.

§Examples
use os_str_bytes::RawOsStr;

fn to_str_lossy<F>(raw: &RawOsStr, mut push: F)
where
    F: FnMut(&str),
{
    for (invalid, string) in raw.utf8_chunks() {
        if !invalid.as_os_str().is_empty() {
            push("\u{FFFD}");
        }

        push(string);
    }
}

Trait Implementations§

source§

impl AsRef<OsStr> for RawOsStr

source§

fn as_ref(&self) -> &OsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for OsStr

source§

fn as_ref(&self) -> &RawOsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for OsString

source§

fn as_ref(&self) -> &RawOsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for RawOsStr

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for RawOsString

source§

fn as_ref(&self) -> &RawOsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for String

source§

fn as_ref(&self) -> &RawOsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<RawOsStr> for str

source§

fn as_ref(&self) -> &RawOsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<RawOsStr> for RawOsString

source§

fn borrow(&self) -> &RawOsStr

Immutably borrows from an owned value. Read more
source§

impl Debug for RawOsStr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for &RawOsStr

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> From<&'a RawOsStr> for Cow<'a, RawOsStr>

source§

fn from(value: &'a RawOsStr) -> Self

Converts to this type from the input type.
source§

impl From<Box<str>> for Box<RawOsStr>

source§

fn from(value: Box<str>) -> Self

Converts to this type from the input type.
source§

impl From<RawOsString> for Box<RawOsStr>

source§

fn from(value: RawOsString) -> Self

Converts to this type from the input type.
source§

impl Hash for RawOsStr

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
source§

impl<Idx> Index<Idx> for RawOsStr
where Idx: SliceIndex,

§

type Output = RawOsStr

The returned type after indexing.
source§

fn index(&self, idx: Idx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Ord for RawOsStr

source§

fn cmp(&self, other: &RawOsStr) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl PartialEq<&RawOsStr> for OsString

source§

fn eq(&self, other: &&RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<&RawOsStr> for RawOsString

source§

fn eq(&self, other: &&RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<&RawOsStr> for String

source§

fn eq(&self, other: &&RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<OsStr> for RawOsStr

source§

fn eq(&self, other: &OsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<OsString> for &RawOsStr

source§

fn eq(&self, other: &OsString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<OsString> for RawOsStr

source§

fn eq(&self, other: &OsString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsStr> for OsStr

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsStr> for OsString

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsStr> for RawOsString

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsStr> for String

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsStr> for str

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsString> for &RawOsStr

source§

fn eq(&self, other: &RawOsString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RawOsString> for RawOsStr

source§

fn eq(&self, other: &RawOsString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for &RawOsStr

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for RawOsStr

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for RawOsStr

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for RawOsStr

source§

fn eq(&self, other: &RawOsStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for RawOsStr

source§

fn partial_cmp(&self, other: &RawOsStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl ToOwned for RawOsStr

§

type Owned = RawOsString

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl Eq for RawOsStr

source§

impl StructuralPartialEq for RawOsStr

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more