Struct UnixStr

Source
pub struct UnixStr { /* private fields */ }
Expand description

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§

Source§

impl UnixStr

Source

pub fn new<S: AsRef<UnixStr> + ?Sized>(s: &S) -> &UnixStr

Coerces into an UnixStr slice.

§Examples
use unix_str::UnixStr;

let unix_str = UnixStr::new("foo");
Source

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

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

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

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

pub fn to_unix_string(&self) -> UnixString

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

pub fn is_empty(&self) -> bool

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

pub fn len(&self) -> usize

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

pub fn into_unix_string(self: Box<UnixStr>) -> UnixString

Converts a Box<UnixStr> into an UnixString without copying allocating.

Source

pub fn from_bytes(slice: &[u8]) -> &Self

Creates a UnixStr from a byte slice.

See the module documentation for an example.

Source

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

Gets the underlying byte view of the UnixStr slice.

See the module documentation for an example.

Trait Implementations§

Source§

impl AsRef<UnixStr> for String

Source§

fn as_ref(&self) -> &UnixStr

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

impl AsRef<UnixStr> for UnixStr

Source§

fn as_ref(&self) -> &UnixStr

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

impl AsRef<UnixStr> for UnixString

Source§

fn as_ref(&self) -> &UnixStr

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

impl AsRef<UnixStr> for str

Source§

fn as_ref(&self) -> &UnixStr

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

impl Borrow<UnixStr> for UnixString

Source§

fn borrow(&self) -> &UnixStr

Immutably borrows from an owned value. Read more
Source§

impl Clone for Box<UnixStr>

Source§

fn clone(&self) -> Self

Returns a copy 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 UnixStr

Source§

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

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

impl Default for &UnixStr

Source§

fn default() -> Self

Creates an empty UnixStr.

Source§

impl Default for Box<UnixStr>

Source§

fn default() -> Self

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

impl From<&UnixStr> for Arc<UnixStr>

Source§

fn from(s: &UnixStr) -> Self

Converts to this type from the input type.
Source§

impl From<&UnixStr> for Box<UnixStr>

Source§

fn from(s: &UnixStr) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(s: &'a UnixStr) -> Self

Converts to this type from the input type.
Source§

impl From<&UnixStr> for Rc<UnixStr>

Source§

fn from(s: &UnixStr) -> Self

Converts to this type from the input type.
Source§

impl From<Cow<'_, UnixStr>> for Box<UnixStr>

Source§

fn from(cow: Cow<'_, UnixStr>) -> Self

Converts to this type from the input type.
Source§

impl From<UnixString> for Box<UnixStr>

Source§

fn from(s: UnixString) -> Self

Converts a UnixString into a Box<UnixStr> without copying or allocating.

Source§

impl Hash for UnixStr

Source§

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

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

impl Ord for UnixStr

Source§

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

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

impl<'a, 'b> PartialEq<&'b UnixStr> for Cow<'a, UnixStr>

Source§

fn eq(&self, other: &&'b UnixStr) -> 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<'a, 'b> PartialEq<&'a UnixStr> for UnixString

Source§

fn eq(&self, other: &&'a UnixStr) -> 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<'a, 'b> PartialEq<Cow<'a, UnixStr>> for &'b UnixStr

Source§

fn eq(&self, other: &Cow<'a, UnixStr>) -> 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<'a, 'b> PartialEq<Cow<'a, UnixStr>> for UnixStr

Source§

fn eq(&self, other: &Cow<'a, UnixStr>) -> 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<'a, 'b> PartialEq<UnixStr> for Cow<'a, UnixStr>

Source§

fn eq(&self, other: &UnixStr) -> 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<'a, 'b> PartialEq<UnixStr> for UnixString

Source§

fn eq(&self, other: &UnixStr) -> 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<UnixStr> for str

Source§

fn eq(&self, other: &UnixStr) -> 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<'a, 'b> PartialEq<UnixString> for &'a UnixStr

Source§

fn eq(&self, other: &UnixString) -> 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<'a, 'b> PartialEq<UnixString> for UnixStr

Source§

fn eq(&self, other: &UnixString) -> 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 UnixStr

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 UnixStr

Source§

fn eq(&self, other: &UnixStr) -> 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<'a, 'b> PartialOrd<&'b UnixStr> for Cow<'a, UnixStr>

Source§

fn partial_cmp(&self, other: &&'b UnixStr) -> 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<'a, 'b> PartialOrd<&'a UnixStr> for UnixString

Source§

fn partial_cmp(&self, other: &&'a UnixStr) -> 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<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for &'b UnixStr

Source§

fn partial_cmp(&self, other: &Cow<'a, UnixStr>) -> 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<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for UnixStr

Source§

fn partial_cmp(&self, other: &Cow<'a, UnixStr>) -> 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<'a, 'b> PartialOrd<UnixStr> for Cow<'a, UnixStr>

Source§

fn partial_cmp(&self, other: &UnixStr) -> 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<'a, 'b> PartialOrd<UnixStr> for UnixString

Source§

fn partial_cmp(&self, other: &UnixStr) -> 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<'a, 'b> PartialOrd<UnixString> for &'a UnixStr

Source§

fn partial_cmp(&self, other: &UnixString) -> 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<'a, 'b> PartialOrd<UnixString> for UnixStr

Source§

fn partial_cmp(&self, other: &UnixString) -> 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 PartialOrd<str> for UnixStr

Source§

fn partial_cmp(&self, other: &str) -> 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 PartialOrd for UnixStr

Source§

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

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

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

Tests less than (for self and other) and is used by the < operator. Read more
Source§

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

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

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

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

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

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

impl ToOwned for UnixStr

Source§

type Owned = UnixString

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 UnixStr

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