Enum pyo3::types::PyStringData
source · [−]Py_LIMITED_API
and little-endian only.Expand description
Represents raw data backing a Python str
.
Python internally stores strings in various representations. This enumeration represents those variations.
Variants
Ucs1(&'a [u8])
UCS1 representation.
Ucs2(&'a [u16])
UCS2 representation.
Ucs4(&'a [u32])
UCS4 representation.
Implementations
sourceimpl<'a> PyStringData<'a>
impl<'a> PyStringData<'a>
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Obtain the raw bytes backing this instance as a u8 slice.
sourcepub fn value_width_bytes(&self) -> usize
pub fn value_width_bytes(&self) -> usize
Size in bytes of each value/item in the underlying slice.
sourcepub fn to_string(self, py: Python<'_>) -> PyResult<Cow<'a, str>>
pub fn to_string(self, py: Python<'_>) -> PyResult<Cow<'a, str>>
Convert the raw data to a Rust string.
For UCS-1 / UTF-8, returns a borrow into the original slice. For UCS-2 and UCS-4, returns an owned string.
Returns PyUnicodeDecodeError if the string data isn’t valid in its purported
storage format. This should only occur for strings that were created via Python
C APIs that skip input validation (like PyUnicode_FromKindAndData
) and should
never occur for strings that were created from Python code.
sourcepub fn to_string_lossy(self) -> Cow<'a, str>
pub fn to_string_lossy(self) -> Cow<'a, str>
Convert the raw data to a Rust string, possibly with data loss.
Invalid code points will be replaced with U+FFFD REPLACEMENT CHARACTER
.
Returns a borrow into original data, when possible, or owned data otherwise.
The return value of this function should only disagree with Self::to_string when that method would error.
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 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for PyStringData<'a>
impl<'a> Debug for PyStringData<'a>
sourceimpl<'a> PartialEq<PyStringData<'a>> for PyStringData<'a>
impl<'a> PartialEq<PyStringData<'a>> for PyStringData<'a>
sourcefn eq(&self, other: &PyStringData<'a>) -> bool
fn eq(&self, other: &PyStringData<'a>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PyStringData<'a>) -> bool
fn ne(&self, other: &PyStringData<'a>) -> bool
This method tests for !=
.
impl<'a> Copy for PyStringData<'a>
impl<'a> StructuralPartialEq 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more