Trait pyo3::impl_::pyclass::PyClassImpl
source · pub trait PyClassImpl: Sized + 'static {
type BaseType: PyTypeInfo + PyClassBaseType;
type PyClassMutability: PyClassMutability + GetBorrowChecker<Self>;
type Dict: PyClassDict;
type WeakRef: PyClassWeakRef;
type BaseNativeType: PyTypeInfo + PyNativeType;
type ThreadChecker: PyClassThreadChecker<Self>;
const IS_BASETYPE: bool = false;
const IS_SUBCLASS: bool = false;
const IS_MAPPING: bool = false;
const IS_SEQUENCE: bool = false;
// Required methods
fn doc(py: Python<'_>) -> PyResult<&'static CStr>;
fn items_iter() -> PyClassItemsIter ⓘ;
fn lazy_type_object() -> &'static LazyTypeObject<Self>;
// Provided methods
fn dict_offset() -> Option<Py_ssize_t> { ... }
fn weaklist_offset() -> Option<Py_ssize_t> { ... }
}
Expand description
Implements the underlying functionality of #[pyclass]
, assembled by various proc macros.
Users are discouraged from implementing this trait manually; it is a PyO3 implementation detail and may be changed at any time.
Required Associated Types§
sourcetype BaseType: PyTypeInfo + PyClassBaseType
type BaseType: PyTypeInfo + PyClassBaseType
Base class
sourcetype PyClassMutability: PyClassMutability + GetBorrowChecker<Self>
type PyClassMutability: PyClassMutability + GetBorrowChecker<Self>
Immutable or mutable
sourcetype Dict: PyClassDict
type Dict: PyClassDict
Specify this class has #[pyclass(dict)]
or not.
sourcetype WeakRef: PyClassWeakRef
type WeakRef: PyClassWeakRef
Specify this class has #[pyclass(weakref)]
or not.
sourcetype BaseNativeType: PyTypeInfo + PyNativeType
type BaseNativeType: PyTypeInfo + PyNativeType
The closest native ancestor. This is PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.
sourcetype ThreadChecker: PyClassThreadChecker<Self>
type ThreadChecker: PyClassThreadChecker<Self>
This handles following two situations:
- In case
T
isSend
, stubThreadChecker
is used and does nothing. This implementation is used by default. Compile fails ifT: !Send
. - In case
T
is!Send
,ThreadChecker
panics whenT
is accessed by another thread. This implementation is used when#[pyclass(unsendable)]
is given. Panicking makes it safe to exposeT: !Send
to the Python interpreter, where all objects can be accessed by multiple threads bythreading
module.
Provided Associated Constants§
sourceconst IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
#[pyclass(subclass)]
sourceconst IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
#[pyclass(extends=…)]
sourceconst IS_MAPPING: bool = false
const IS_MAPPING: bool = false
#[pyclass(mapping)]
sourceconst IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
#[pyclass(sequence)]
Required Methods§
fn items_iter() -> PyClassItemsIter ⓘ
fn lazy_type_object() -> &'static LazyTypeObject<Self>
Provided Methods§
fn dict_offset() -> Option<Py_ssize_t>
fn weaklist_offset() -> Option<Py_ssize_t>
Object Safety§
This trait is not object safe.
Implementors§
source§impl PyClassImpl for Coroutine
Available on crate feature experimental-async
only.
impl PyClassImpl for Coroutine
Available on crate feature
experimental-async
only.