pub unsafe trait PyTypeInfo: Sized {
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<'_>) -> Bound<'_, PyType> { ... }
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType> { ... }
fn is_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_exact_type_of_bound(object: &Bound<'_, 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 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<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Returns the safe abstraction over the type object.
Sourcefn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
👎Deprecated since 0.23.0: renamed to PyTypeInfo::type_object
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_object
Deprecated name for PyTypeInfo::type_object
.
Sourcefn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
Checks if object
is an instance of this type or a subclass of this type.
Sourcefn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_type_of
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_of
Deprecated name for PyTypeInfo::is_type_of
.
Sourcefn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
Checks if object
is an instance of this type.
Sourcefn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_exact_type_of
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_of
Deprecated name for PyTypeInfo::is_exact_type_of
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.