RawOsString

Struct RawOsString 

Source
pub struct RawOsString(/* private fields */);
Expand description

A container for owned byte strings converted by this crate.

For more information, see RawOsStr.

Implementations§

Source§

impl RawOsString

Source

pub fn new(string: OsString) -> Self

Converts a platform-native string into a representation that can be more easily manipulated.

For more information, see RawOsStr::new.

§Nightly Notes

This method does not require copying or encoding conversion.

§Examples
use std::env;

use os_str_bytes::RawOsString;

let os_string = env::current_exe()?.into_os_string();
println!("{:?}", RawOsString::new(os_string));
Source

pub fn from_string(string: String) -> Self

Wraps a string, without copying or encoding conversion.

This method is much more efficient than RawOsString::new, since the encoding used by this crate is compatible with UTF-8.

§Examples
use os_str_bytes::RawOsString;

let string = "foobar".to_owned();
let raw = RawOsString::from_string(string.clone());
assert_eq!(string, raw);
Source

pub fn assert_from_raw_vec(string: Vec<u8>) -> Self

👎Deprecated: enable the ‘conversions’ feature

Wraps a byte string, without copying or encoding conversion.

§Panics

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

§Examples
use std::env;

use os_str_bytes::RawOsString;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsString::new(os_string);
let raw_bytes = raw.clone().into_raw_vec();
assert_eq!(raw, RawOsString::assert_from_raw_vec(raw_bytes));
Source

pub unsafe fn from_raw_vec_unchecked(string: Vec<u8>) -> Self

👎Deprecated: enable the ‘conversions’ feature

Wraps a byte string, without copying or encoding conversion.

§Safety

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

§Nightly Notes

This method is deprecated. Use assert_from_raw_vec or from_encoded_vec_unchecked instead.

§Examples
use std::env;

use os_str_bytes::RawOsString;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsString::new(os_string);
let raw_bytes = raw.clone().into_raw_vec();
assert_eq!(raw, unsafe {
    RawOsString::from_raw_vec_unchecked(raw_bytes)
});
Source

pub fn clear(&mut self)

Equivalent to String::clear.

§Examples
use std::env;

use os_str_bytes::RawOsString;

let os_string = env::current_exe()?.into_os_string();
let mut raw = RawOsString::new(os_string);
raw.clear();
assert!(raw.is_empty());
Source

pub fn into_box(self) -> Box<RawOsStr>

Equivalent to String::into_boxed_str.

§Examples
use os_str_bytes::RawOsString;

let string = "foobar".to_owned();
let raw = RawOsString::from_string(string.clone());
assert_eq!(string, *raw.into_box());
Source

pub fn into_os_string(self) -> OsString

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::RawOsString;

let os_string = env::current_exe()?.into_os_string();
let raw = RawOsString::new(os_string.clone());
assert_eq!(os_string, raw.into_os_string());
Source

pub fn into_raw_vec(self) -> Vec<u8>

👎Deprecated: enable the ‘conversions’ feature

Returns the byte string stored by this container.

The returned string will use an unspecified encoding.

§Examples
use os_str_bytes::RawOsString;

let string = "foobar".to_owned();
let raw = RawOsString::from_string(string.clone());
assert_eq!(string.into_bytes(), raw.into_raw_vec());
Source

pub fn into_string(self) -> Result<String, Self>

Equivalent to OsString::into_string.

§Examples
use os_str_bytes::RawOsString;

let string = "foobar".to_owned();
let raw = RawOsString::from_string(string.clone());
assert_eq!(Ok(string), raw.into_string());
Source

pub fn shrink_to_fit(&mut self)

Equivalent to String::shrink_to_fit.

§Examples
use os_str_bytes::RawOsString;

let string = "foobar".to_owned();
let mut raw = RawOsString::from_string(string.clone());
raw.shrink_to_fit();
assert_eq!(string, raw);
Source

pub fn split_off(&mut self, at: usize) -> Self

Equivalent to String::split_off.

§Panics

Panics if the index is not a valid boundary.

§Examples
use os_str_bytes::RawOsString;

let mut raw = RawOsString::from_string("foobar".to_owned());
assert_eq!("bar", raw.split_off(3));
assert_eq!("foo", raw);
Source

pub fn truncate(&mut self, new_len: usize)

Equivalent to String::truncate.

§Panics

Panics if the index is not a valid boundary.

§Examples
use os_str_bytes::RawOsString;

let mut raw = RawOsString::from_string("foobar".to_owned());
raw.truncate(3);
assert_eq!("foo", raw);

Methods from Deref<Target = RawOsStr>§

Source

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

👎Deprecated: enable the ‘conversions’ feature

Returns the byte string stored by this container.

The returned string will use an unspecified encoding.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::from_str(string);
assert_eq!(string.as_bytes(), raw.as_raw_bytes());
Source

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

Equivalent to str::contains.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::ends_with.

§Examples
use os_str_bytes::RawOsStr;

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

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

👎Deprecated: enable the ‘conversions’ feature

Equivalent to str::ends_with but accepts this type for the pattern.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::find.

§Examples
use os_str_bytes::RawOsStr;

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

pub fn is_empty(&self) -> bool

Equivalent to str::is_empty.

§Examples
use os_str_bytes::RawOsStr;

assert!(RawOsStr::from_str("").is_empty());
assert!(!RawOsStr::from_str("foobar").is_empty());
Source

pub fn raw_len(&self) -> usize

👎Deprecated: enable the ‘conversions’ feature

Returns the length of the byte string stored by this container.

Only the following assumptions can be made about the result:

  • The length of any Unicode character is the length of its UTF-8 representation (i.e., char::len_utf8).
  • Splitting a string at a UTF-8 boundary will return two strings with lengths that sum to the length of the original string.

This method may return a different result than would OsStr::len when called on same string, since OsStr uses an unspecified encoding.

§Examples
use os_str_bytes::RawOsStr;

assert_eq!(6, RawOsStr::from_str("foobar").raw_len());
assert_eq!(0, RawOsStr::from_str("").raw_len());
Source

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

Equivalent to str::rfind.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::rsplit_once.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("foobar");
assert_eq!(
    Some((RawOsStr::from_str("fo"), RawOsStr::from_str("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 str::split, but empty patterns are not accepted.

§Panics

Panics if the pattern is empty.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::split_at.

§Panics

Panics if the index is not a valid boundary.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::split_once.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("foobar");
assert_eq!(
    Some((RawOsStr::from_str("f"), RawOsStr::from_str("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 str::starts_with.

§Examples
use os_str_bytes::RawOsStr;

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

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

👎Deprecated: enable the ‘conversions’ feature

Equivalent to str::starts_with but accepts this type for the pattern.

§Examples
use os_str_bytes::RawOsStr;

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

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

Equivalent to str::strip_prefix.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("111foo1bar111");
assert_eq!(
    Some(RawOsStr::from_str("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 str::strip_suffix.

§Examples
use os_str_bytes::RawOsStr;

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

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

Converts this representation back to a platform-native string.

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

§Nightly Notes

This method is deprecated. Use as_os_str instead.

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

👎Deprecated: enable the ‘conversions’ feature

Converts and returns the byte string stored by this container.

The returned string will use an unspecified encoding.

§Examples
use os_str_bytes::RawOsStr;

let string = "foobar";
let raw = RawOsStr::from_str(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::from_str(string);
assert_eq!(Some(string), raw.to_str());
Source

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

Converts this string to the best UTF-8 representation possible.

Invalid sequences will be replaced with char::REPLACEMENT_CHARACTER.

This method may return a different result than would OsStr::to_string_lossy when called on same string, since OsStr uses an unspecified encoding.

§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 str::trim_end_matches.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("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 str::trim_matches.

§Examples
use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("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 str::trim_start_matches.

§Examples
use os_str_bytes::RawOsStr;

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

Trait Implementations§

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 Borrow<RawOsStr> for RawOsString

Source§

fn borrow(&self) -> &RawOsStr

Immutably borrows from an owned value. Read more
Source§

impl Clone for RawOsString

Source§

fn clone(&self) -> RawOsString

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RawOsString

Source§

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

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

impl Default for RawOsString

Source§

fn default() -> RawOsString

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

impl Deref for RawOsString

Source§

type Target = RawOsStr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Box<RawOsStr>> for RawOsString

Source§

fn from(value: Box<RawOsStr>) -> 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 From<RawOsString> for Cow<'_, RawOsStr>

Source§

fn from(value: RawOsString) -> Self

Converts to this type from the input type.
Source§

impl From<String> for RawOsString

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for RawOsString

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<Range<usize>> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

fn index(&self, idx: Range<usize>) -> &Self::Output

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

impl Index<RangeFrom<usize>> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

fn index(&self, idx: RangeFrom<usize>) -> &Self::Output

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

impl Index<RangeFull> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

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

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

impl Index<RangeInclusive<usize>> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

fn index(&self, idx: RangeInclusive<usize>) -> &Self::Output

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

impl Index<RangeTo<usize>> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

fn index(&self, idx: RangeTo<usize>) -> &Self::Output

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

impl Index<RangeToInclusive<usize>> for RawOsString

Source§

type Output = RawOsStr

The returned type after indexing.
Source§

fn index(&self, idx: RangeToInclusive<usize>) -> &Self::Output

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

impl Ord for RawOsString

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<&RawOsStr> for RawOsString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for RawOsString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RawOsString> for &str

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RawOsString> for String

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RawOsString> for str

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for RawOsString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for RawOsString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for RawOsString

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RawOsString

Source§

fn partial_cmp(&self, other: &RawOsString) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for RawOsString

Source§

impl StructuralPartialEq for RawOsString

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes