Trait pyo3::type_object::PyTypeInfo
source · pub unsafe trait PyTypeInfo: Sized {
type AsRefTarget: PyNativeType;
const NAME: &'static str;
const MODULE: Option<&'static str>;
// Required method
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject;
// Provided methods
fn type_object(py: Python<'_>) -> &PyType { ... }
fn is_type_of(object: &PyAny) -> bool { ... }
fn is_exact_type_of(object: &PyAny) -> bool { ... }
}
Expand description
Python type information.
All Python native types (e.g., PyDict
) and #[pyclass]
structs implement this trait.
This trait is marked unsafe because:
- specifying the incorrect layout can lead to memory errors
- the return value of type_object must always point to the same PyTypeObject instance
It is safely implemented by the pyclass
macro.
Safety
Implementations must provide an implementation for type_object_raw
which infallibly produces a
non-null pointer to the corresponding Python type object.
Required Associated Types§
sourcetype AsRefTarget: PyNativeType
type AsRefTarget: PyNativeType
Utility type to make Py::as_ref work.
Required Associated Constants§
Required Methods§
sourcefn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Returns the PyTypeObject instance for this type.
Provided Methods§
sourcefn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
Returns the safe abstraction over the type object.
sourcefn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
Checks if object
is an instance of this type or a subclass of this type.
sourcefn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
Checks if object
is an instance of this type.