pyo3::impl_::pyclass

Trait 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;
    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§

Source

const IS_BASETYPE: bool = false

#[pyclass(subclass)]

Source

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]

Source

const IS_MAPPING: bool = false

#[pyclass(mapping)]

Source

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]

Required Associated Types§

Source

type BaseType: PyTypeInfo + PyClassBaseType

Base class

Source

type PyClassMutability: PyClassMutability + GetBorrowChecker<Self>

Immutable or mutable

Source

type Dict: PyClassDict

Specify this class has #[pyclass(dict)] or not.

Source

type WeakRef: PyClassWeakRef

Specify this class has #[pyclass(weakref)] or not.

Source

type BaseNativeType: PyTypeInfo

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.

Source

type ThreadChecker: PyClassThreadChecker<Self>

This handles following two situations:

  1. In case T is Send, stub ThreadChecker is used and does nothing. This implementation is used by default. Compile fails if T: !Send.
  2. In case T is !Send, ThreadChecker panics when T is accessed by another thread. This implementation is used when #[pyclass(unsendable)] is given. Panicking makes it safe to expose T: !Send to the Python interpreter, where all objects can be accessed by multiple threads by threading module.

Required Methods§

Source

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc

Source

fn items_iter() -> PyClassItemsIter

Source

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Provided Methods§

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§

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here