Struct cpython::PyUnicode [−][src]
Represents a Python unicode string.
Corresponds to unicode
in Python 2, and str
in Python 3.
Implementations
impl PyUnicode
[src]
pub fn new(py: Python<'_>, s: &str) -> PyUnicode
[src]
Creates a new Python unicode string object.
Panics if out of memory.
pub fn as_basestring(&self) -> &PyString
[src]
Converts from PyUnicode
to PyString
.
This method is only available on Python 2.
(note: on Python 3, PyUnicode
is a type alias for PyString
)
pub fn into_basestring(self) -> PyString
[src]
Converts from PyUnicode
to PyString
.
This method is only available on Python 2.
(note: on Python 3, PyUnicode
is a type alias for PyString
)
pub fn data(&self, _py: Python<'_>) -> PyStringData<'_>
[src]
Gets the python string data in its underlying representation.
pub fn to_string(&self, py: Python<'_>) -> PyResult<Cow<'_, str>>
[src]
Convert the PyUnicode
into a Rust string.
Returns a UnicodeDecodeError
if the input is not valid unicode
(containing unpaired surrogates).
pub fn to_string_lossy(&self, py: Python<'_>) -> Cow<'_, str>
[src]
Convert the PyUnicode
into a Rust string.
Unpaired surrogates are replaced with U+FFFD REPLACEMENT CHARACTER.
Trait Implementations
impl<'s> FromPyObject<'s> for PyUnicode
[src]
impl<'s> FromPyObject<'s> for &'s PyUnicode
[src]
impl PythonObject for PyUnicode
[src]
fn as_object(&self) -> &PyObject
[src]
fn into_object(self) -> PyObject
[src]
unsafe fn unchecked_downcast_from(obj: PyObject) -> Self
[src]
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
[src]
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
impl PythonObjectWithCheckedDowncast for PyUnicode
[src]
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyUnicode, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: PyObject
) -> Result<PyUnicode, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyUnicode, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyUnicode, PythonObjectDowncastError<'p>>
impl PythonObjectWithTypeObject for PyUnicode
[src]
fn type_object(py: Python<'_>) -> PyType
[src]
impl ToPyObject for PyUnicode
[src]
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
type ObjectType = PyUnicode
fn to_py_object(&self, py: Python<'_>) -> PyUnicode
[src]
fn into_py_object(self, _py: Python<'_>) -> PyUnicode
[src]
fn with_borrowed_ptr<F, R>(&self, _py: Python<'_>, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
Auto Trait Implementations
impl RefUnwindSafe for PyUnicode
[src]
impl Send for PyUnicode
[src]
impl Sync for PyUnicode
[src]
impl Unpin for PyUnicode
[src]
impl UnwindSafe for PyUnicode
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,