Struct clap_lex::RawOsString
source · [−]pub struct RawOsString(_);
Expand description
A container for the byte strings converted by OsStringBytes
.
For more information, see RawOsStr
.
Implementations
sourceimpl RawOsString
impl RawOsString
sourcepub fn new(string: OsString) -> RawOsString
pub fn new(string: OsString) -> RawOsString
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));
sourcepub fn from_string(string: String) -> RawOsString
pub fn from_string(string: String) -> RawOsString
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);
sourcepub fn into_os_string(self) -> OsString
pub fn into_os_string(self) -> OsString
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());
sourcepub fn into_raw_vec(self) -> Vec<u8, Global>
pub fn into_raw_vec(self) -> Vec<u8, Global>
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());
sourcepub fn into_string(self) -> Result<String, RawOsString>
pub fn into_string(self) -> Result<String, RawOsString>
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());
Methods from Deref<Target = RawOsStr>
sourcepub fn as_raw_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn as_raw_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
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());
sourcepub fn contains<P>(&self, pat: P) -> bool where
P: Pattern,
pub fn contains<P>(&self, pat: P) -> bool where
P: Pattern,
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"));
sourcepub fn ends_with<P>(&self, pat: P) -> bool where
P: Pattern,
pub fn ends_with<P>(&self, pat: P) -> bool where
P: Pattern,
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"));
sourcepub fn ends_with_os(&self, pat: &RawOsStr) -> bool
pub fn ends_with_os(&self, pat: &RawOsStr) -> bool
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")));
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn raw_len(&self) -> usize
pub fn raw_len(&self) -> usize
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());
sourcepub fn rfind<P>(&self, pat: P) -> Option<usize> where
P: Pattern,
pub fn rfind<P>(&self, pat: P) -> Option<usize> where
P: Pattern,
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"));
sourcepub fn rsplit_once<P>(&self, pat: P) -> Option<(&RawOsStr, &RawOsStr)> where
P: Pattern,
pub fn rsplit_once<P>(&self, pat: P) -> Option<(&RawOsStr, &RawOsStr)> where
P: Pattern,
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"));
sourcepub fn split<P>(&self, pat: P) -> Split<'_, P> where
P: Pattern,
pub fn split<P>(&self, pat: P) -> Split<'_, P> where
P: Pattern,
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<_>>());
sourcepub fn split_at(&self, mid: usize) -> (&RawOsStr, &RawOsStr)
pub fn split_at(&self, mid: usize) -> (&RawOsStr, &RawOsStr)
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),
);
sourcepub fn split_once<P>(&self, pat: P) -> Option<(&RawOsStr, &RawOsStr)> where
P: Pattern,
pub fn split_once<P>(&self, pat: P) -> Option<(&RawOsStr, &RawOsStr)> where
P: Pattern,
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"));
sourcepub fn starts_with<P>(&self, pat: P) -> bool where
P: Pattern,
pub fn starts_with<P>(&self, pat: P) -> bool where
P: Pattern,
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"));
sourcepub fn starts_with_os(&self, pat: &RawOsStr) -> bool
pub fn starts_with_os(&self, pat: &RawOsStr) -> bool
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")));
sourcepub fn strip_prefix<P>(&self, pat: P) -> Option<&RawOsStr> where
P: Pattern,
pub fn strip_prefix<P>(&self, pat: P) -> Option<&RawOsStr> where
P: Pattern,
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"));
sourcepub fn strip_suffix<P>(&self, pat: P) -> Option<&RawOsStr> where
P: Pattern,
pub fn strip_suffix<P>(&self, pat: P) -> Option<&RawOsStr> where
P: Pattern,
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"));
sourcepub fn to_os_str(&self) -> Cow<'_, OsStr>
pub fn to_os_str(&self) -> Cow<'_, OsStr>
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());
sourcepub fn to_str(&self) -> Option<&str>
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());
sourcepub fn to_str_lossy(&self) -> Cow<'_, str>
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());
sourcepub fn trim_end_matches<P>(&self, pat: P) -> &RawOsStr where
P: Pattern,
pub fn trim_end_matches<P>(&self, pat: P) -> &RawOsStr where
P: Pattern,
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"));
sourcepub fn trim_start_matches<P>(&self, pat: P) -> &RawOsStr where
P: Pattern,
pub fn trim_start_matches<P>(&self, pat: P) -> &RawOsStr where
P: Pattern,
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
sourceimpl AsRef<RawOsStr> for RawOsString
impl AsRef<RawOsStr> for RawOsString
sourceimpl Borrow<RawOsStr> for RawOsString
impl Borrow<RawOsStr> for RawOsString
sourceimpl Clone for RawOsString
impl Clone for RawOsString
sourcefn clone(&self) -> RawOsString
fn clone(&self) -> RawOsString
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for RawOsString
impl Debug for RawOsString
sourceimpl Default for RawOsString
impl Default for RawOsString
sourcefn default() -> RawOsString
fn default() -> RawOsString
Returns the “default value” for a type. Read more
sourceimpl Deref for RawOsString
impl Deref for RawOsString
sourceimpl From<String> for RawOsString
impl From<String> for RawOsString
sourcefn from(other: String) -> RawOsString
fn from(other: String) -> RawOsString
Converts to this type from the input type.
sourceimpl Hash for RawOsString
impl Hash for RawOsString
sourceimpl Index<Range<usize>> for RawOsString
impl Index<Range<usize>> for RawOsString
sourceimpl Index<RangeFrom<usize>> for RawOsString
impl Index<RangeFrom<usize>> for RawOsString
sourceimpl Index<RangeFull> for RawOsString
impl Index<RangeFull> for RawOsString
sourceimpl Index<RangeInclusive<usize>> for RawOsString
impl Index<RangeInclusive<usize>> for RawOsString
sourcefn index(
&self,
idx: RangeInclusive<usize>
) -> &<RawOsString as Index<RangeInclusive<usize>>>::Output
fn index(
&self,
idx: RangeInclusive<usize>
) -> &<RawOsString as Index<RangeInclusive<usize>>>::Output
Performs the indexing (container[index]
) operation. Read more
sourceimpl Index<RangeTo<usize>> for RawOsString
impl Index<RangeTo<usize>> for RawOsString
sourceimpl Index<RangeToInclusive<usize>> for RawOsString
impl Index<RangeToInclusive<usize>> for RawOsString
sourcefn index(
&self,
idx: RangeToInclusive<usize>
) -> &<RawOsString as Index<RangeToInclusive<usize>>>::Output
fn index(
&self,
idx: RangeToInclusive<usize>
) -> &<RawOsString as Index<RangeToInclusive<usize>>>::Output
Performs the indexing (container[index]
) operation. Read more
sourceimpl Ord for RawOsString
impl Ord for RawOsString
sourceimpl<'_> PartialEq<&RawOsStr> for RawOsString
impl<'_> PartialEq<&RawOsStr> for RawOsString
sourceimpl<'_> PartialEq<&str> for RawOsString
impl<'_> PartialEq<&str> for RawOsString
sourceimpl PartialEq<RawOsStr> for RawOsString
impl PartialEq<RawOsStr> for RawOsString
sourceimpl PartialEq<RawOsString> for RawOsStr
impl PartialEq<RawOsString> for RawOsStr
sourceimpl PartialEq<RawOsString> for RawOsString
impl PartialEq<RawOsString> for RawOsString
sourcefn eq(&self, other: &RawOsString) -> bool
fn eq(&self, other: &RawOsString) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &RawOsString) -> bool
fn ne(&self, other: &RawOsString) -> bool
This method tests for !=
.
sourceimpl<'_> PartialEq<RawOsString> for &str
impl<'_> PartialEq<RawOsString> for &str
sourceimpl<'_> PartialEq<RawOsString> for &RawOsStr
impl<'_> PartialEq<RawOsString> for &RawOsStr
sourceimpl PartialEq<RawOsString> for str
impl PartialEq<RawOsString> for str
sourceimpl PartialEq<String> for RawOsString
impl PartialEq<String> for RawOsString
sourceimpl PartialEq<str> for RawOsString
impl PartialEq<str> for RawOsString
sourceimpl PartialOrd<RawOsString> for RawOsString
impl PartialOrd<RawOsString> for RawOsString
sourcefn partial_cmp(&self, other: &RawOsString) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Eq for RawOsString
impl StructuralEq for RawOsString
impl StructuralPartialEq for RawOsString
Auto Trait Implementations
impl RefUnwindSafe for RawOsString
impl Send for RawOsString
impl Sync for RawOsString
impl Unpin for RawOsString
impl UnwindSafe for RawOsString
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more