pub struct PyString(_);
Expand description

Represents a Python string. Corresponds to basestring in Python 2, and str in Python 3.

Implementations

Creates a new Python string object.

On Python 2.7, this function will create a byte string if the feature py2-no-auto-unicode-promotion is set, or the input input string is ASCII-only; otherwise, the input string will be converted to a unicode string. Use PyUnicode::new() to always create a unicode string.

On Python 3.x, this function always creates unicode str objects.

Panics if out of memory.

Gets the python string data in its underlying representation.

For Python 2 byte strings, this function always returns PyStringData::Utf8, even if the bytes are not valid UTF-8. For unicode strings, returns the underlying representation used by Python.

Convert the PyString into a Rust string.

On Python 2.7, if the PyString refers to a byte string, it will be decoded using UTF-8.

Returns a UnicodeDecodeError if the input is not valid unicode (containing unpaired surrogates, or a Python 2.7 byte string that is not valid UTF-8).

Convert the PyString into a Rust string.

On Python 2.7, if the PyString refers to a byte string, it will be decoded using UTF-8.

Unpaired surrogates and (on Python 2.7) invalid UTF-8 sequences are replaced with U+FFFD REPLACEMENT CHARACTER.

Trait Implementations

Extracts Self from the source PyObject.
Extracts Self from the source PyObject.

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

Casts the Python object to PyObject.
Casts the Python object to PyObject.
Cast from PyObject to a concrete Python object type.
Cast from PyObject to a concrete Python object type.
Retrieves the type object for this Python object type.

Identity conversion: allows using existing PyObject instances where T: ToPyObject is expected.

Converts self into a Python object.
Converts self into a Python object. Read more
Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object. Read more

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 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.