Struct pyo3::exceptions::PyUnicodeDecodeError
source · pub struct PyUnicodeDecodeError(PyAny);
Expand description
Represents Python’s UnicodeDecodeError
exception.
Tuple Fields§
§0: PyAny
Implementations§
source§impl PyUnicodeDecodeError
impl PyUnicodeDecodeError
#[doc(hidden)] pub const _PYO3_DEF: AddTypeToModule<Self> = _
source§impl PyUnicodeDecodeError
impl PyUnicodeDecodeError
sourcepub fn new_bound<'p>(
py: Python<'p>,
encoding: &CStr,
input: &[u8],
range: Range<usize>,
reason: &CStr
) -> PyResult<Bound<'p, PyUnicodeDecodeError>>
pub fn new_bound<'p>( py: Python<'p>, encoding: &CStr, input: &[u8], range: Range<usize>, reason: &CStr ) -> PyResult<Bound<'p, PyUnicodeDecodeError>>
Creates a Python UnicodeDecodeError
.
sourcepub fn new_utf8_bound<'p>(
py: Python<'p>,
input: &[u8],
err: Utf8Error
) -> PyResult<Bound<'p, PyUnicodeDecodeError>>
pub fn new_utf8_bound<'p>( py: Python<'p>, input: &[u8], err: Utf8Error ) -> PyResult<Bound<'p, PyUnicodeDecodeError>>
Creates a Python UnicodeDecodeError
from a Rust UTF-8 decoding error.
§Examples
#![cfg_attr(invalid_from_utf8_lint, allow(invalid_from_utf8))]
use pyo3::prelude::*;
use pyo3::exceptions::PyUnicodeDecodeError;
Python::with_gil(|py| {
let invalid_utf8 = b"fo\xd8o";
let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8");
let decode_err = PyUnicodeDecodeError::new_utf8_bound(py, invalid_utf8, err)?;
assert_eq!(
decode_err.to_string(),
"'utf-8' codec can't decode byte 0xd8 in position 2: invalid utf-8"
);
Ok(())
})
Methods from Deref<Target = PyAny>§
#[doc(hidden)] pub const _PYO3_DEF: AddTypeToModule<Self> = _
Trait Implementations§
source§impl AsPyPointer for PyUnicodeDecodeError
impl AsPyPointer for PyUnicodeDecodeError
source§impl AsRef<PyAny> for PyUnicodeDecodeError
impl AsRef<PyAny> for PyUnicodeDecodeError
source§impl Deref for PyUnicodeDecodeError
impl Deref for PyUnicodeDecodeError
source§impl PyTypeInfo for PyUnicodeDecodeError
impl PyTypeInfo for PyUnicodeDecodeError
source§const NAME: &'static str = "PyUnicodeDecodeError"
const NAME: &'static str = "PyUnicodeDecodeError"
Available on non-crate feature
gil-refs
only.Class name.
source§const MODULE: Option<&'static str> = _
const MODULE: Option<&'static str> = _
Available on non-crate feature
gil-refs
only.Module name, if any.
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Available on non-crate feature
gil-refs
only.Returns the PyTypeObject instance for this type.
source§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
Available on non-crate feature
gil-refs
only.Returns the safe abstraction over the type object.
impl DerefToPyAny for PyUnicodeDecodeError
impl PyLayout<PyUnicodeDecodeError> for PyBaseExceptionObject
impl PySizedLayout<PyUnicodeDecodeError> for PyBaseExceptionObject
impl ToPyErr for PyUnicodeDecodeError
Auto Trait Implementations§
impl !Freeze for PyUnicodeDecodeError
impl !RefUnwindSafe for PyUnicodeDecodeError
impl !Send for PyUnicodeDecodeError
impl !Sync for PyUnicodeDecodeError
impl Unpin for PyUnicodeDecodeError
impl UnwindSafe for PyUnicodeDecodeError
Blanket Implementations§
source§impl<T> AssertNotZeroSized for T
impl<T> AssertNotZeroSized for T
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more