[][src]Struct unix_str::UnixStr

pub struct UnixStr { /* fields omitted */ }

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]

Coerces into an UnixStr slice.

Examples

use unix_str::UnixStr;

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

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]

fn default() -> Self[src]

Creates an empty UnixStr.

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]

impl Ord for UnixStr[src]

impl<'a, 'b> PartialEq<&'a UnixStr> for UnixString[src]

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

impl<'a, 'b> PartialEq<Cow<'a, UnixStr>> for UnixStr[src]

impl<'a, 'b> PartialEq<Cow<'a, UnixStr>> for &'b UnixStr[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]

impl<'a, 'b> PartialEq<UnixString> for &'a UnixStr[src]

impl PartialEq<str> for UnixStr[src]

impl<'a, 'b> PartialOrd<&'a UnixStr> for UnixString[src]

impl<'a, 'b> PartialOrd<&'b UnixStr> for Cow<'a, UnixStr>[src]

impl<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for UnixStr[src]

impl<'a, 'b> PartialOrd<Cow<'a, UnixStr>> for &'b UnixStr[src]

impl PartialOrd<UnixStr> for UnixStr[src]

impl<'a, 'b> PartialOrd<UnixStr> for UnixString[src]

impl<'a, 'b> PartialOrd<UnixStr> for Cow<'a, UnixStr>[src]

impl<'a, 'b> PartialOrd<UnixString> for UnixStr[src]

impl<'a, 'b> PartialOrd<UnixString> for &'a UnixStr[src]

impl PartialOrd<str> for UnixStr[src]

impl ToOwned for UnixStr[src]

type Owned = UnixString

The resulting type after obtaining ownership.

Auto Trait Implementations

impl Send for UnixStr

impl Sync for UnixStr

impl Unpin for UnixStr

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.