Skip to main content

PyClassImpl

Trait PyClassImpl 

Source
pub trait PyClassImpl: Sized + 'static {
    type Layout: PyClassObjectLayout<Self>;
    type BaseType: PyTypeInfo + PyClassBaseType;
    type PyClassMutability: PyClassMutability + GetBorrowChecker<Self>;
    type Dict: PyClassDict;
    type WeakRef: PyClassWeakRef;
    type BaseNativeType: PyTypeInfo;
    type ThreadChecker: PyClassThreadChecker<Self>;
Show 8 associated constants and 4 methods const MODULE: Option<&'static str>; const RAW_DOC: &'static CStr; const DOC: &'static CStr; const IS_BASETYPE: bool = false; const IS_SUBCLASS: bool = false; const IS_MAPPING: bool = false; const IS_SEQUENCE: bool = false; const IS_IMMUTABLE_TYPE: bool = false; // Required methods fn items_iter() -> PyClassItemsIter ; fn lazy_type_object() -> &'static LazyTypeObject<Self>; // Provided methods fn dict_offset() -> Option<PyObjectOffset> { ... } fn weaklist_offset() -> Option<PyObjectOffset> { ... }
}
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 Constants§

Source

const MODULE: Option<&'static str>

Module which the class will be associated with.

(Currently defaults to builtins if unset, this will likely be improved in the future, it may also be removed when passing module objects in class init.)

Source

const RAW_DOC: &'static CStr

Docstring for the class provided on the struct or enum.

This is exposed for PyClassDocGenerator to use as a docstring piece.

Source

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined.

This is constructed at compile-time with const specialization via the proc macros with help from the PyClassDocGenerator` type.

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)]

Source

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]

Required Associated Types§

Source

type Layout: PyClassObjectLayout<Self>

Description of how this class is laid out in memory

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§

Provided Methods§

Source

fn dict_offset() -> Option<PyObjectOffset>

Used to provide the dictoffset slot (equivalent to tp_dictoffset)

Source

fn weaklist_offset() -> Option<PyObjectOffset>

Used to provide the weaklistoffset slot (equivalent to tp_weaklistoffset

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.
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here