Enum cpython::PyStringData
source · pub enum PyStringData<'a> {
Latin1(&'a [u8]),
Utf8(&'a [u8]),
Utf16(&'a [u16]),
Utf32(&'a [u32]),
}
Expand description
Enum of possible Python string representations.
Variants§
Implementations§
source§impl<'a> PyStringData<'a>
impl<'a> PyStringData<'a>
sourcepub fn to_string(self, py: Python<'_>) -> PyResult<Cow<'a, str>>
pub fn to_string(self, py: Python<'_>) -> PyResult<Cow<'a, str>>
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.
sourcepub fn to_string_lossy(self) -> Cow<'a, str>
pub fn to_string_lossy(self) -> Cow<'a, str>
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§
source§impl<'a> Clone for PyStringData<'a>
impl<'a> Clone for PyStringData<'a>
source§fn clone(&self) -> PyStringData<'a>
fn clone(&self) -> PyStringData<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for PyStringData<'a>
impl<'a> Debug for PyStringData<'a>
source§impl<'a> From<&'a [u16]> for PyStringData<'a>
impl<'a> From<&'a [u16]> for PyStringData<'a>
source§fn from(val: &'a [u16]) -> PyStringData<'a>
fn from(val: &'a [u16]) -> PyStringData<'a>
Converts to this type from the input type.
source§impl<'a> From<&'a [u32]> for PyStringData<'a>
impl<'a> From<&'a [u32]> for PyStringData<'a>
source§fn from(val: &'a [u32]) -> PyStringData<'a>
fn from(val: &'a [u32]) -> PyStringData<'a>
Converts to this type from the input type.
source§impl<'a> From<&'a str> for PyStringData<'a>
impl<'a> From<&'a str> for PyStringData<'a>
source§fn from(val: &'a str) -> PyStringData<'a>
fn from(val: &'a str) -> PyStringData<'a>
Converts to this type from the input type.
impl<'a> Copy for PyStringData<'a>
Auto Trait Implementations§
impl<'a> Freeze for PyStringData<'a>
impl<'a> RefUnwindSafe for PyStringData<'a>
impl<'a> Send for PyStringData<'a>
impl<'a> Sync for PyStringData<'a>
impl<'a> Unpin for PyStringData<'a>
impl<'a> UnwindSafe for PyStringData<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more