Struct os_str_bytes::RawOsString[][src]

pub struct RawOsString(_);
This is supported on crate feature raw_os_str only.
Expand description

A container for the byte strings converted by OsStringBytes.

For more information, see RawOsStr.

Implementations

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

For more information, see RawOsStr::new.

Examples

use std::env;

use os_str_bytes::RawOsString;

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

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_string();
let raw = RawOsString::from_string(string.clone());
assert_eq!(string, raw);

Converts this representation back to a platform-native string.

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());

Returns the byte string stored by this container.

The result will match what would be returned by OsStringBytes::into_raw_vec for the same string.

Examples

use std::env;

use os_str_bytes::OsStringBytes;
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.into_raw_vec(), raw.into_raw_vec());

Equivalent to OsString::into_string.

Examples

use os_str_bytes::RawOsString;

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

Methods from Deref<Target = RawOsStr>

Returns the byte string stored by this container.

The result will match what would be returned by OsStrBytes::to_raw_bytes for the same string.

Examples

use std::env;

use os_str_bytes::OsStrBytes;
use os_str_bytes::RawOsStr;

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

Equivalent to str::contains.

Panics

Panics if the pattern is a byte outside of the ASCII range.

Examples

use os_str_bytes::RawOsStr;

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

Equivalent to str::ends_with.

Panics

Panics if the pattern is a byte outside of the ASCII range.

Examples

use os_str_bytes::RawOsStr;

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

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

Panics

Panics if the pattern is a byte outside of the ASCII range.

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")));

Equivalent to str::find.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::is_empty.

Examples

use os_str_bytes::RawOsStr;

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

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());

Equivalent to str::rfind.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::rsplit_once.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::split, but empty patterns are not accepted.

Panics

Panics if the pattern is a byte outside of the ASCII range or empty.

Examples

use os_str_bytes::RawOsStr;

let raw = RawOsStr::from_str("foobar");
assert_eq!(["f", "", "bar"], *raw.split("o").collect::<Vec<_>>());

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),
);

Equivalent to str::split_once.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::starts_with.

Panics

Panics if the pattern is a byte outside of the ASCII range.

Examples

use os_str_bytes::RawOsStr;

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

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

Panics

Panics if the pattern is a byte outside of the ASCII range.

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")));

Equivalent to str::strip_prefix.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::strip_suffix.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Converts this representation back to a platform-native string.

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());

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());

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());

Equivalent to str::trim_end_matches.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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"));

Equivalent to str::trim_start_matches.

Panics

Panics if the pattern is a byte outside of the ASCII range.

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

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

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

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

Escapes a string using the format described in the the module-level documentation, without the surrounding quotes. Read more

Quotes a string using the format described in the the module-level documentation. Read more

Creates a byte sequence that will be used to represent the instance.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.