Enum cpython::PyStringData
source · [−]Expand description
Enum of possible Python string representations.
Variants
Latin1(&'a [u8])
Utf8(&'a [u8])
Utf16(&'a [u16])
Utf32(&'a [u32])
Implementations
sourceimpl<'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
sourceimpl<'a> Clone for PyStringData<'a>
impl<'a> Clone for PyStringData<'a>
sourcefn clone(&self) -> PyStringData<'a>
fn clone(&self) -> PyStringData<'a>
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<'a> Debug for PyStringData<'a>
impl<'a> Debug for PyStringData<'a>
sourceimpl<'a> From<&'a [u16]> for PyStringData<'a>
impl<'a> From<&'a [u16]> for PyStringData<'a>
sourcefn from(val: &'a [u16]) -> PyStringData<'a>
fn from(val: &'a [u16]) -> PyStringData<'a>
Converts to this type from the input type.
sourceimpl<'a> From<&'a [u32]> for PyStringData<'a>
impl<'a> From<&'a [u32]> for PyStringData<'a>
sourcefn from(val: &'a [u32]) -> PyStringData<'a>
fn from(val: &'a [u32]) -> PyStringData<'a>
Converts to this type from the input type.
sourceimpl<'a> From<&'a str> for PyStringData<'a>
impl<'a> From<&'a str> for PyStringData<'a>
sourcefn 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> 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more