use crate::conversion::PyTryFrom;
use crate::err::PyDowncastError;
use crate::internal_tricks::Unsendable;
use crate::{ffi, PyObject};
#[repr(transparent)]
pub struct PyAny(PyObject, Unsendable);
unsafe impl crate::type_object::PyLayout<PyAny> for ffi::PyObject {}
impl crate::type_object::PySizedLayout<PyAny> for ffi::PyObject {}
pyobject_native_type_named!(PyAny);
pyobject_native_type_convert!(
PyAny,
ffi::PyObject,
ffi::PyBaseObject_Type,
Some("builtins"),
ffi::PyObject_Check
);
pyobject_native_type_extract!(PyAny);
impl PyAny {
pub fn downcast<T>(&self) -> Result<&T, PyDowncastError>
where
for<'py> T: PyTryFrom<'py>,
{
<T as PyTryFrom>::try_from(self)
}
}