pub trait PyClassImpl: Sized + 'static {
type BaseType: PyTypeInfo + PyClassBaseType;
type PyClassMutability: PyClassMutability + GetBorrowChecker<Self>;
type Dict: PyClassDict;
type WeakRef: PyClassWeakRef;
type BaseNativeType: PyTypeInfo;
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.
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 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
type BaseNativeType: PyTypeInfo
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.
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>
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.
Implementors§
Source§impl PyClassImpl for Coroutine
Available on crate feature experimental-async
only.
impl PyClassImpl for Coroutine
Available on crate feature
experimental-async
only.