pub unsafe trait PyTypeInfo: Sized {
    type AsRefTarget: PyNativeType;

    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<'_>) -> &PyType { ... }
    fn is_type_of(object: &PyAny) -> bool { ... }
    fn is_exact_type_of(object: &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 Types§

source

type AsRefTarget: PyNativeType

Utility type to make Py::as_ref work.

Required Associated Constants§

source

const NAME: &'static str

Class name.

source

const MODULE: Option<&'static str>

Module name, if any.

Required Methods§

source

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.

Provided Methods§

source

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.

source

fn is_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type or a subclass of this type.

source

fn is_exact_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type.

Implementors§

source§

impl PyTypeInfo for CancelledError

§

type AsRefTarget = CancelledError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for IncompleteReadError

§

type AsRefTarget = IncompleteReadError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for InvalidStateError

§

type AsRefTarget = InvalidStateError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for LimitOverrunError

§

type AsRefTarget = LimitOverrunError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for QueueEmpty

§

type AsRefTarget = QueueEmpty

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for QueueFull

§

type AsRefTarget = QueueFull

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for TimeoutError

§

type AsRefTarget = TimeoutError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for gaierror

§

type AsRefTarget = gaierror

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for herror

§

type AsRefTarget = herror

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for timeout

§

type AsRefTarget = timeout

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyArithmeticError

§

type AsRefTarget = PyArithmeticError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyAssertionError

§

type AsRefTarget = PyAssertionError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyAttributeError

§

type AsRefTarget = PyAttributeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBaseException

§

type AsRefTarget = PyBaseException

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBlockingIOError

§

type AsRefTarget = PyBlockingIOError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBrokenPipeError

§

type AsRefTarget = PyBrokenPipeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBufferError

§

type AsRefTarget = PyBufferError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBytesWarning

§

type AsRefTarget = PyBytesWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyChildProcessError

§

type AsRefTarget = PyChildProcessError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyConnectionAbortedError

§

type AsRefTarget = PyConnectionAbortedError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyConnectionError

§

type AsRefTarget = PyConnectionError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyConnectionRefusedError

§

type AsRefTarget = PyConnectionRefusedError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyConnectionResetError

§

type AsRefTarget = PyConnectionResetError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDeprecationWarning

§

type AsRefTarget = PyDeprecationWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyEOFError

§

type AsRefTarget = PyEOFError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyEncodingWarning

§

type AsRefTarget = PyEncodingWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyEnvironmentError

§

type AsRefTarget = PyEnvironmentError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyException

§

type AsRefTarget = PyException

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFileExistsError

§

type AsRefTarget = PyFileExistsError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFileNotFoundError

§

type AsRefTarget = PyFileNotFoundError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFloatingPointError

§

type AsRefTarget = PyFloatingPointError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFutureWarning

§

type AsRefTarget = PyFutureWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyGeneratorExit

§

type AsRefTarget = PyGeneratorExit

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyIOError

§

type AsRefTarget = PyIOError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyImportError

§

type AsRefTarget = PyImportError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyImportWarning

§

type AsRefTarget = PyImportWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyIndexError

§

type AsRefTarget = PyIndexError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyInterruptedError

§

type AsRefTarget = PyInterruptedError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyIsADirectoryError

§

type AsRefTarget = PyIsADirectoryError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyKeyError

§

type AsRefTarget = PyKeyError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyKeyboardInterrupt

§

type AsRefTarget = PyKeyboardInterrupt

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyLookupError

§

type AsRefTarget = PyLookupError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyMemoryError

§

type AsRefTarget = PyMemoryError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyModuleNotFoundError

§

type AsRefTarget = PyModuleNotFoundError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyNameError

§

type AsRefTarget = PyNameError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyNotADirectoryError

§

type AsRefTarget = PyNotADirectoryError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyNotImplementedError

§

type AsRefTarget = PyNotImplementedError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyOSError

§

type AsRefTarget = PyOSError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyOverflowError

§

type AsRefTarget = PyOverflowError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyPendingDeprecationWarning

§

type AsRefTarget = PyPendingDeprecationWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyPermissionError

§

type AsRefTarget = PyPermissionError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyProcessLookupError

§

type AsRefTarget = PyProcessLookupError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyRecursionError

§

type AsRefTarget = PyRecursionError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyReferenceError

§

type AsRefTarget = PyReferenceError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyResourceWarning

§

type AsRefTarget = PyResourceWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyRuntimeError

§

type AsRefTarget = PyRuntimeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyRuntimeWarning

§

type AsRefTarget = PyRuntimeWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyStopAsyncIteration

§

type AsRefTarget = PyStopAsyncIteration

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyStopIteration

§

type AsRefTarget = PyStopIteration

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySyntaxError

§

type AsRefTarget = PySyntaxError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySyntaxWarning

§

type AsRefTarget = PySyntaxWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySystemError

§

type AsRefTarget = PySystemError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySystemExit

§

type AsRefTarget = PySystemExit

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTimeoutError

§

type AsRefTarget = PyTimeoutError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTypeError

§

type AsRefTarget = PyTypeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnboundLocalError

§

type AsRefTarget = PyUnboundLocalError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnicodeDecodeError

§

type AsRefTarget = PyUnicodeDecodeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnicodeEncodeError

§

type AsRefTarget = PyUnicodeEncodeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnicodeError

§

type AsRefTarget = PyUnicodeError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnicodeTranslateError

§

type AsRefTarget = PyUnicodeTranslateError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUnicodeWarning

§

type AsRefTarget = PyUnicodeWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyUserWarning

§

type AsRefTarget = PyUserWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyValueError

§

type AsRefTarget = PyValueError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyWarning

§

type AsRefTarget = PyWarning

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyZeroDivisionError

§

type AsRefTarget = PyZeroDivisionError

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PanicException

§

type AsRefTarget = PanicException

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyAny

§

type AsRefTarget = PyAny

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBool

§

type AsRefTarget = PyBool

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyByteArray

§

type AsRefTarget = PyByteArray

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyBytes

§

type AsRefTarget = PyBytes

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyCFunction

§

type AsRefTarget = PyCFunction

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyCapsule

§

type AsRefTarget = PyCapsule

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyCode

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyCode

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyComplex

§

type AsRefTarget = PyComplex

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDate

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyDate

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDateTime

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyDateTime

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDelta

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyDelta

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDict

§

type AsRefTarget = PyDict

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDictItems

§

type AsRefTarget = PyDictItems

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDictKeys

§

type AsRefTarget = PyDictKeys

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyDictValues

§

type AsRefTarget = PyDictValues

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFloat

§

type AsRefTarget = PyFloat

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFrame

Available on non-Py_LIMITED_API and non-PyPy only.
§

type AsRefTarget = PyFrame

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFrozenSet

§

type AsRefTarget = PyFrozenSet

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyFunction

§

type AsRefTarget = PyFunction

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyList

§

type AsRefTarget = PyList

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyLong

§

type AsRefTarget = PyLong

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyModule

§

type AsRefTarget = PyModule

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySet

§

type AsRefTarget = PySet

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySlice

§

type AsRefTarget = PySlice

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyString

§

type AsRefTarget = PyString

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PySuper

Available on non-PyPy only.
§

type AsRefTarget = PySuper

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTime

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyTime

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTraceback

§

type AsRefTarget = PyTraceback

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTuple

§

type AsRefTarget = PyTuple

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyType

§

type AsRefTarget = PyType

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _

source§

impl PyTypeInfo for PyTzInfo

Available on non-Py_LIMITED_API only.
§

type AsRefTarget = PyTzInfo

source§

const NAME: &'static str = _

source§

const MODULE: Option<&'static str> = _