Enum cpython::PyStringData[][src]

pub enum PyStringData<'a> {
    Latin1(&'a [u8]),
    Utf8(&'a [u8]),
    Utf16(&'a [u16]),
    Utf32(&'a [u32]),
}

Enum of possible Python string representations.

Variants

Latin1(&'a [u8])
Utf8(&'a [u8])
Utf16(&'a [u16])
Utf32(&'a [u32])

Implementations

impl<'a> PyStringData<'a>[src]

pub fn to_string(self, py: Python<'_>) -> PyResult<Cow<'a, str>>[src]

Convert the Python string data to a Rust string.

For UTF-8 and ASCII-only latin-1, returns a borrow into the original string data. For Latin-1, UTF-16 and UTF-32, returns an owned string.

Fails with UnicodeDecodeError if the string data isn't valid in its encoding.

pub fn to_string_lossy(self) -> Cow<'a, str>[src]

Convert the Python string data to a Rust string.

Returns a borrow into the original string data if possible.

Data that isn't valid in its encoding will be replaced with U+FFFD REPLACEMENT CHARACTER.

Trait Implementations

impl<'a> Clone for PyStringData<'a>[src]

impl<'a> Copy for PyStringData<'a>[src]

impl<'a> Debug for PyStringData<'a>[src]

impl<'a> From<&'a [u16]> for PyStringData<'a>[src]

impl<'a> From<&'a [u32]> for PyStringData<'a>[src]

impl<'a> From<&'a str> for PyStringData<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for PyStringData<'a>[src]

impl<'a> Send for PyStringData<'a>[src]

impl<'a> Sync for PyStringData<'a>[src]

impl<'a> Unpin for PyStringData<'a>[src]

impl<'a> UnwindSafe for PyStringData<'a>[src]

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> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.