[−][src]Struct cpython::PyString
Represents a Python string.
Corresponds to basestring
in Python 2, and str
in Python 3.
Methods
impl PyString
[src]
pub fn new(py: Python, s: &str) -> PyString
[src]
Creates a new Python string object.
On Python 2.7, this function will create a byte string if the
input string is ASCII-only; and a unicode string otherwise.
Use PyUnicode::new()
to always create a unicode string.
Panics if out of memory.
pub fn data(&self, py: Python) -> PyStringData
[src]
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.
pub fn to_string(&self, py: Python) -> PyResult<Cow<str>>
[src]
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).
pub fn to_string_lossy(&self, py: Python) -> Cow<str>
[src]
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
impl PythonObject for PyString
[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 PyString
[src]
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyString, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: PyObject
) -> Result<PyString, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyString, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyString, PythonObjectDowncastError<'p>>
impl PythonObjectWithTypeObject for PyString
[src]
fn type_object(py: Python) -> PyType
[src]
impl ToPyObject for PyString
[src]
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
type ObjectType = PyString
fn to_py_object(&self, py: Python) -> PyString
[src]
fn into_py_object(self, _py: Python) -> PyString
[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,
impl<'source> FromPyObject<'source> for PyString
[src]
impl<'source> FromPyObject<'source> for &'source PyString
[src]
Auto Trait Implementations
impl Sync for PyString
impl Send for PyString
impl Unpin for PyString
impl RefUnwindSafe for PyString
impl UnwindSafe for PyString
Blanket Implementations
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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,