pub enum PyStringData<'a> {
    Ucs1(&'a [u8]),
    Ucs2(&'a [u16]),
    Ucs4(&'a [u32]),
}
This is supported on non-Py_LIMITED_API and little-endian only.
Expand description

Represents raw data backing a Python str.

Python internally stores strings in various representations. This enumeration represents those variations.

Variants

Ucs1(&'a [u8])

UCS1 representation.

Ucs2(&'a [u16])

UCS2 representation.

Ucs4(&'a [u32])

UCS4 representation.

Implementations

Obtain the raw bytes backing this instance as a u8 slice.

Size in bytes of each value/item in the underlying slice.

Convert the raw data to a Rust string.

For UCS-1 / UTF-8, returns a borrow into the original slice. For UCS-2 and UCS-4, returns an owned string.

Returns PyUnicodeDecodeError if the string data isn’t valid in its purported storage format. This should only occur for strings that were created via Python C APIs that skip input validation (like PyUnicode_FromKindAndData) and should never occur for strings that were created from Python code.

Convert the raw data to a Rust string, possibly with data loss.

Invalid code points will be replaced with U+FFFD REPLACEMENT CHARACTER.

Returns a borrow into original data, when possible, or owned data otherwise.

The return value of this function should only disagree with Self::to_string when that method would error.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.