[−][src]Struct unix_str::UnixStr
Borrowed reference to a Unix string (see UnixString
).
This type represents a borrowed reference to a string in Unix's preferred representation.
&UnixStr
is to UnixString
as &str
is to String
: the former
in each pair are borrowed references; the latter are owned strings.
See the module's toplevel documentation about conversions
for a discussion on the traits which UnixStr
implements for conversions
from/to native representations.
Implementations
impl UnixStr
[src]
pub fn new<S: AsRef<UnixStr> + ?Sized>(s: &S) -> &UnixStr
[src]
pub fn to_str(&self) -> Option<&str>
[src]
Yields a &str
slice if the UnixStr
is valid Unicode.
This conversion may entail doing a check for UTF-8 validity.
Examples
use unix_str::UnixStr; let unix_str = UnixStr::new("foo"); assert_eq!(unix_str.to_str(), Some("foo"));
pub fn to_string_lossy(&self) -> Cow<str>
[src]
Converts an UnixStr
to a Cow<str>
.
Any non-Unicode sequences are replaced with
U+FFFD REPLACEMENT CHARACTER
.
Examples
Calling to_string_lossy
on an UnixStr
with invalid unicode:
use unix_str::UnixStr; // Here, the values 0x66 and 0x6f correspond to 'f' and 'o' // respectively. The value 0x80 is a lone continuation byte, invalid // in a UTF-8 sequence. let source = [0x66, 0x6f, 0x80, 0x6f]; let unix_str = UnixStr::from_bytes(&source[..]); assert_eq!(unix_str.to_string_lossy(), "fo�o");
pub fn to_unix_string(&self) -> UnixString
[src]
Copies the slice into an owned UnixString
.
Examples
use unix_str::{UnixStr, UnixString}; let unix_str = UnixStr::new("foo"); let unix_string = unix_str.to_unix_string(); assert_eq!(unix_string, UnixString::from("foo"));
pub fn is_empty(&self) -> bool
[src]
Checks whether the UnixStr
is empty.
Examples
use unix_str::UnixStr; let unix_str = UnixStr::new(""); assert!(unix_str.is_empty()); let unix_str = UnixStr::new("foo"); assert!(!unix_str.is_empty());
pub fn len(&self) -> usize
[src]
Returns the length of this UnixStr
.
Note that this does not return the number of bytes in the string in OS string form.
The length returned is that of the underlying storage used by UnixStr
.
As discussed in the UnixString
introduction, UnixString
and
UnixStr
store strings in a form best suited for cheap inter-conversion
between native-platform and Rust string forms, which may differ
significantly from both of them, including in storage size and encoding.
This number is simply useful for passing to other methods, like
UnixString::with_capacity
to avoid reallocations.
Examples
use unix_str::UnixStr; let unix_str = UnixStr::new(""); assert_eq!(unix_str.len(), 0); let unix_str = UnixStr::new("foo"); assert_eq!(unix_str.len(), 3);
pub fn into_unix_string(self: Box<UnixStr>) -> UnixString
[src]
Converts a Box<UnixStr>
into an UnixString
without copying
allocating.
pub fn from_bytes(slice: &[u8]) -> &Self
[src]
Creates a UnixStr
from a byte slice.
See the module documentation for an example.
pub fn as_bytes(&self) -> &[u8]
[src]
Gets the underlying byte view of the UnixStr
slice.
See the module documentation for an example.
Trait Implementations
impl AsRef<UnixStr> for UnixStr
[src]
impl AsRef<UnixStr> for UnixString
[src]
impl AsRef<UnixStr> for str
[src]
impl AsRef<UnixStr> for String
[src]
impl Borrow<UnixStr> for UnixString
[src]
impl Debug for UnixStr
[src]
impl<'_> Default for &'_ UnixStr
[src]
impl Eq for UnixStr
[src]
impl<'_> From<&'_ UnixStr> for Box<UnixStr>
[src]
impl<'_> From<&'_ UnixStr> for Arc<UnixStr>
[src]
impl<'_> From<&'_ UnixStr> for Rc<UnixStr>
[src]
impl<'a> From<&'a UnixStr> for Cow<'a, UnixStr>
[src]
impl Hash for UnixStr
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for UnixStr
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a, 'b> PartialEq<&'a UnixStr> for UnixString
[src]
fn eq(&self, other: &&'a UnixStr) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialEq<&'b UnixStr> for Cow<'a, UnixStr>
[src]
fn eq(&self, other: &&'b UnixStr) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialEq<Cow<'a, UnixStr>> for UnixStr
[src]
fn eq(&self, other: &Cow<'a, UnixStr>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialEq<Cow<'a, UnixStr>> for &'b UnixStr
[src]
fn eq(&self, other: &Cow<'a, UnixStr>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<UnixStr> for UnixStr
[src]
impl PartialEq<UnixStr> for str
[src]
impl<'a, 'b> PartialEq<UnixStr> for UnixString
[src]
impl<'a, 'b> PartialEq<UnixStr> for Cow<'a, UnixStr>
[src]
impl<'a, 'b> PartialEq<UnixString> for UnixStr
[src]
fn eq(&self, other: &UnixString) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialEq<UnixString> for &'a UnixStr
[src]
fn eq(&self, other: &UnixString) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<str> for UnixStr
[src]
impl<'a, 'b> PartialOrd<&'a UnixStr> for UnixString
[src]
fn partial_cmp(&self, other: &&'a UnixStr) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<&'b UnixStr> for Cow<'a, UnixStr>
[src]
fn partial_cmp(&self, other: &&'b UnixStr) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for UnixStr
[src]
fn partial_cmp(&self, other: &Cow<'a, UnixStr>) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for &'b UnixStr
[src]
fn partial_cmp(&self, other: &Cow<'a, UnixStr>) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<UnixStr> for UnixStr
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn lt(&self, other: &Self) -> bool
[src]
fn le(&self, other: &Self) -> bool
[src]
fn gt(&self, other: &Self) -> bool
[src]
fn ge(&self, other: &Self) -> bool
[src]
impl<'a, 'b> PartialOrd<UnixStr> for UnixString
[src]
fn partial_cmp(&self, other: &UnixStr) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<UnixStr> for Cow<'a, UnixStr>
[src]
fn partial_cmp(&self, other: &UnixStr) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<UnixString> for UnixStr
[src]
fn partial_cmp(&self, other: &UnixString) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'b> PartialOrd<UnixString> for &'a UnixStr
[src]
fn partial_cmp(&self, other: &UnixString) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<str> for UnixStr
[src]
fn partial_cmp(&self, other: &str) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl ToOwned for UnixStr
[src]
type Owned = UnixString
The resulting type after obtaining ownership.
fn to_owned(&self) -> Self::Owned
[src]
fn clone_into(&self, target: &mut Self::Owned)
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.