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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl PyTypeInfo for CancelledError

§

type AsRefTarget = CancelledError

source§

const NAME: &'static str = "CancelledError"

source§

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

source§

impl PyTypeInfo for IncompleteReadError

§

type AsRefTarget = IncompleteReadError

source§

const NAME: &'static str = "IncompleteReadError"

source§

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

source§

impl PyTypeInfo for InvalidStateError

§

type AsRefTarget = InvalidStateError

source§

const NAME: &'static str = "InvalidStateError"

source§

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

source§

impl PyTypeInfo for LimitOverrunError

§

type AsRefTarget = LimitOverrunError

source§

const NAME: &'static str = "LimitOverrunError"

source§

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

source§

impl PyTypeInfo for QueueEmpty

§

type AsRefTarget = QueueEmpty

source§

const NAME: &'static str = "QueueEmpty"

source§

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

source§

impl PyTypeInfo for QueueFull

§

type AsRefTarget = QueueFull

source§

const NAME: &'static str = "QueueFull"

source§

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

source§

impl PyTypeInfo for TimeoutError

§

type AsRefTarget = TimeoutError

source§

const NAME: &'static str = "TimeoutError"

source§

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

source§

impl PyTypeInfo for gaierror

§

type AsRefTarget = gaierror

source§

const NAME: &'static str = "gaierror"

source§

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

source§

impl PyTypeInfo for herror

§

type AsRefTarget = herror

source§

const NAME: &'static str = "herror"

source§

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

source§

impl PyTypeInfo for timeout

§

type AsRefTarget = timeout

source§

const NAME: &'static str = "timeout"

source§

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

source§

impl PyTypeInfo for PyArithmeticError

§

type AsRefTarget = PyArithmeticError

source§

const NAME: &'static str = "PyArithmeticError"

source§

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

source§

impl PyTypeInfo for PyAssertionError

§

type AsRefTarget = PyAssertionError

source§

const NAME: &'static str = "PyAssertionError"

source§

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

source§

impl PyTypeInfo for PyAttributeError

§

type AsRefTarget = PyAttributeError

source§

const NAME: &'static str = "PyAttributeError"

source§

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

source§

impl PyTypeInfo for PyBaseException

§

type AsRefTarget = PyBaseException

source§

const NAME: &'static str = "PyBaseException"

source§

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

source§

impl PyTypeInfo for PyBlockingIOError

§

type AsRefTarget = PyBlockingIOError

source§

const NAME: &'static str = "PyBlockingIOError"

source§

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

source§

impl PyTypeInfo for PyBrokenPipeError

§

type AsRefTarget = PyBrokenPipeError

source§

const NAME: &'static str = "PyBrokenPipeError"

source§

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

source§

impl PyTypeInfo for PyBufferError

§

type AsRefTarget = PyBufferError

source§

const NAME: &'static str = "PyBufferError"

source§

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

source§

impl PyTypeInfo for PyBytesWarning

§

type AsRefTarget = PyBytesWarning

source§

const NAME: &'static str = "PyBytesWarning"

source§

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

source§

impl PyTypeInfo for PyChildProcessError

§

type AsRefTarget = PyChildProcessError

source§

const NAME: &'static str = "PyChildProcessError"

source§

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

source§

impl PyTypeInfo for PyConnectionAbortedError

§

type AsRefTarget = PyConnectionAbortedError

source§

const NAME: &'static str = "PyConnectionAbortedError"

source§

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

source§

impl PyTypeInfo for PyConnectionError

§

type AsRefTarget = PyConnectionError

source§

const NAME: &'static str = "PyConnectionError"

source§

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

source§

impl PyTypeInfo for PyConnectionRefusedError

§

type AsRefTarget = PyConnectionRefusedError

source§

const NAME: &'static str = "PyConnectionRefusedError"

source§

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

source§

impl PyTypeInfo for PyConnectionResetError

§

type AsRefTarget = PyConnectionResetError

source§

const NAME: &'static str = "PyConnectionResetError"

source§

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

source§

impl PyTypeInfo for PyDeprecationWarning

§

type AsRefTarget = PyDeprecationWarning

source§

const NAME: &'static str = "PyDeprecationWarning"

source§

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

source§

impl PyTypeInfo for PyEOFError

§

type AsRefTarget = PyEOFError

source§

const NAME: &'static str = "PyEOFError"

source§

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

source§

impl PyTypeInfo for PyEncodingWarning

§

type AsRefTarget = PyEncodingWarning

source§

const NAME: &'static str = "PyEncodingWarning"

source§

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

source§

impl PyTypeInfo for PyEnvironmentError

§

type AsRefTarget = PyEnvironmentError

source§

const NAME: &'static str = "PyEnvironmentError"

source§

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

source§

impl PyTypeInfo for PyException

§

type AsRefTarget = PyException

source§

const NAME: &'static str = "PyException"

source§

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

source§

impl PyTypeInfo for PyFileExistsError

§

type AsRefTarget = PyFileExistsError

source§

const NAME: &'static str = "PyFileExistsError"

source§

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

source§

impl PyTypeInfo for PyFileNotFoundError

§

type AsRefTarget = PyFileNotFoundError

source§

const NAME: &'static str = "PyFileNotFoundError"

source§

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

source§

impl PyTypeInfo for PyFloatingPointError

§

type AsRefTarget = PyFloatingPointError

source§

const NAME: &'static str = "PyFloatingPointError"

source§

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

source§

impl PyTypeInfo for PyFutureWarning

§

type AsRefTarget = PyFutureWarning

source§

const NAME: &'static str = "PyFutureWarning"

source§

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

source§

impl PyTypeInfo for PyGeneratorExit

§

type AsRefTarget = PyGeneratorExit

source§

const NAME: &'static str = "PyGeneratorExit"

source§

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

source§

impl PyTypeInfo for PyIOError

§

type AsRefTarget = PyIOError

source§

const NAME: &'static str = "PyIOError"

source§

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

source§

impl PyTypeInfo for PyImportError

§

type AsRefTarget = PyImportError

source§

const NAME: &'static str = "PyImportError"

source§

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

source§

impl PyTypeInfo for PyImportWarning

§

type AsRefTarget = PyImportWarning

source§

const NAME: &'static str = "PyImportWarning"

source§

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

source§

impl PyTypeInfo for PyIndexError

§

type AsRefTarget = PyIndexError

source§

const NAME: &'static str = "PyIndexError"

source§

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

source§

impl PyTypeInfo for PyInterruptedError

§

type AsRefTarget = PyInterruptedError

source§

const NAME: &'static str = "PyInterruptedError"

source§

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

source§

impl PyTypeInfo for PyIsADirectoryError

§

type AsRefTarget = PyIsADirectoryError

source§

const NAME: &'static str = "PyIsADirectoryError"

source§

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

source§

impl PyTypeInfo for PyKeyError

§

type AsRefTarget = PyKeyError

source§

const NAME: &'static str = "PyKeyError"

source§

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

source§

impl PyTypeInfo for PyKeyboardInterrupt

§

type AsRefTarget = PyKeyboardInterrupt

source§

const NAME: &'static str = "PyKeyboardInterrupt"

source§

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

source§

impl PyTypeInfo for PyLookupError

§

type AsRefTarget = PyLookupError

source§

const NAME: &'static str = "PyLookupError"

source§

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

source§

impl PyTypeInfo for PyMemoryError

§

type AsRefTarget = PyMemoryError

source§

const NAME: &'static str = "PyMemoryError"

source§

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

source§

impl PyTypeInfo for PyModuleNotFoundError

§

type AsRefTarget = PyModuleNotFoundError

source§

const NAME: &'static str = "PyModuleNotFoundError"

source§

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

source§

impl PyTypeInfo for PyNameError

§

type AsRefTarget = PyNameError

source§

const NAME: &'static str = "PyNameError"

source§

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

source§

impl PyTypeInfo for PyNotADirectoryError

§

type AsRefTarget = PyNotADirectoryError

source§

const NAME: &'static str = "PyNotADirectoryError"

source§

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

source§

impl PyTypeInfo for PyNotImplementedError

§

type AsRefTarget = PyNotImplementedError

source§

const NAME: &'static str = "PyNotImplementedError"

source§

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

source§

impl PyTypeInfo for PyOSError

§

type AsRefTarget = PyOSError

source§

const NAME: &'static str = "PyOSError"

source§

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

source§

impl PyTypeInfo for PyOverflowError

§

type AsRefTarget = PyOverflowError

source§

const NAME: &'static str = "PyOverflowError"

source§

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

source§

impl PyTypeInfo for PyPendingDeprecationWarning

§

type AsRefTarget = PyPendingDeprecationWarning

source§

const NAME: &'static str = "PyPendingDeprecationWarning"

source§

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

source§

impl PyTypeInfo for PyPermissionError

§

type AsRefTarget = PyPermissionError

source§

const NAME: &'static str = "PyPermissionError"

source§

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

source§

impl PyTypeInfo for PyProcessLookupError

§

type AsRefTarget = PyProcessLookupError

source§

const NAME: &'static str = "PyProcessLookupError"

source§

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

source§

impl PyTypeInfo for PyRecursionError

§

type AsRefTarget = PyRecursionError

source§

const NAME: &'static str = "PyRecursionError"

source§

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

source§

impl PyTypeInfo for PyReferenceError

§

type AsRefTarget = PyReferenceError

source§

const NAME: &'static str = "PyReferenceError"

source§

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

source§

impl PyTypeInfo for PyResourceWarning

§

type AsRefTarget = PyResourceWarning

source§

const NAME: &'static str = "PyResourceWarning"

source§

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

source§

impl PyTypeInfo for PyRuntimeError

§

type AsRefTarget = PyRuntimeError

source§

const NAME: &'static str = "PyRuntimeError"

source§

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

source§

impl PyTypeInfo for PyRuntimeWarning

§

type AsRefTarget = PyRuntimeWarning

source§

const NAME: &'static str = "PyRuntimeWarning"

source§

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

source§

impl PyTypeInfo for PyStopAsyncIteration

§

type AsRefTarget = PyStopAsyncIteration

source§

const NAME: &'static str = "PyStopAsyncIteration"

source§

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

source§

impl PyTypeInfo for PyStopIteration

§

type AsRefTarget = PyStopIteration

source§

const NAME: &'static str = "PyStopIteration"

source§

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

source§

impl PyTypeInfo for PySyntaxError

§

type AsRefTarget = PySyntaxError

source§

const NAME: &'static str = "PySyntaxError"

source§

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

source§

impl PyTypeInfo for PySyntaxWarning

§

type AsRefTarget = PySyntaxWarning

source§

const NAME: &'static str = "PySyntaxWarning"

source§

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

source§

impl PyTypeInfo for PySystemError

§

type AsRefTarget = PySystemError

source§

const NAME: &'static str = "PySystemError"

source§

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

source§

impl PyTypeInfo for PySystemExit

§

type AsRefTarget = PySystemExit

source§

const NAME: &'static str = "PySystemExit"

source§

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

source§

impl PyTypeInfo for PyTimeoutError

§

type AsRefTarget = PyTimeoutError

source§

const NAME: &'static str = "PyTimeoutError"

source§

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

source§

impl PyTypeInfo for PyTypeError

§

type AsRefTarget = PyTypeError

source§

const NAME: &'static str = "PyTypeError"

source§

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

source§

impl PyTypeInfo for PyUnboundLocalError

§

type AsRefTarget = PyUnboundLocalError

source§

const NAME: &'static str = "PyUnboundLocalError"

source§

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

source§

impl PyTypeInfo for PyUnicodeDecodeError

§

type AsRefTarget = PyUnicodeDecodeError

source§

const NAME: &'static str = "PyUnicodeDecodeError"

source§

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

source§

impl PyTypeInfo for PyUnicodeEncodeError

§

type AsRefTarget = PyUnicodeEncodeError

source§

const NAME: &'static str = "PyUnicodeEncodeError"

source§

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

source§

impl PyTypeInfo for PyUnicodeError

§

type AsRefTarget = PyUnicodeError

source§

const NAME: &'static str = "PyUnicodeError"

source§

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

source§

impl PyTypeInfo for PyUnicodeTranslateError

§

type AsRefTarget = PyUnicodeTranslateError

source§

const NAME: &'static str = "PyUnicodeTranslateError"

source§

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

source§

impl PyTypeInfo for PyUnicodeWarning

§

type AsRefTarget = PyUnicodeWarning

source§

const NAME: &'static str = "PyUnicodeWarning"

source§

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

source§

impl PyTypeInfo for PyUserWarning

§

type AsRefTarget = PyUserWarning

source§

const NAME: &'static str = "PyUserWarning"

source§

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

source§

impl PyTypeInfo for PyValueError

§

type AsRefTarget = PyValueError

source§

const NAME: &'static str = "PyValueError"

source§

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

source§

impl PyTypeInfo for PyWarning

§

type AsRefTarget = PyWarning

source§

const NAME: &'static str = "PyWarning"

source§

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

source§

impl PyTypeInfo for PyZeroDivisionError

§

type AsRefTarget = PyZeroDivisionError

source§

const NAME: &'static str = "PyZeroDivisionError"

source§

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

source§

impl PyTypeInfo for PanicException

§

type AsRefTarget = PanicException

source§

const NAME: &'static str = "PanicException"

source§

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

source§

impl PyTypeInfo for PyAny

§

type AsRefTarget = PyAny

source§

const NAME: &'static str = "PyAny"

source§

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

source§

impl PyTypeInfo for PyBool

§

type AsRefTarget = PyBool

source§

const NAME: &'static str = "PyBool"

source§

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

source§

impl PyTypeInfo for PyByteArray

§

type AsRefTarget = PyByteArray

source§

const NAME: &'static str = "PyByteArray"

source§

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

source§

impl PyTypeInfo for PyBytes

§

type AsRefTarget = PyBytes

source§

const NAME: &'static str = "PyBytes"

source§

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

source§

impl PyTypeInfo for PyCFunction

§

type AsRefTarget = PyCFunction

source§

const NAME: &'static str = "PyCFunction"

source§

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

source§

impl PyTypeInfo for PyCapsule

§

type AsRefTarget = PyCapsule

source§

const NAME: &'static str = "PyCapsule"

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 = "PyCode"

source§

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

source§

impl PyTypeInfo for PyComplex

§

type AsRefTarget = PyComplex

source§

const NAME: &'static str = "PyComplex"

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 = "PyDate"

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 = "PyDateTime"

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 = "PyDelta"

source§

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

source§

impl PyTypeInfo for PyDict

§

type AsRefTarget = PyDict

source§

const NAME: &'static str = "PyDict"

source§

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

source§

impl PyTypeInfo for PyDictItems

§

type AsRefTarget = PyDictItems

source§

const NAME: &'static str = "PyDictItems"

source§

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

source§

impl PyTypeInfo for PyDictKeys

§

type AsRefTarget = PyDictKeys

source§

const NAME: &'static str = "PyDictKeys"

source§

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

source§

impl PyTypeInfo for PyDictValues

§

type AsRefTarget = PyDictValues

source§

const NAME: &'static str = "PyDictValues"

source§

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

source§

impl PyTypeInfo for PyFloat

§

type AsRefTarget = PyFloat

source§

const NAME: &'static str = "PyFloat"

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 = "PyFrame"

source§

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

source§

impl PyTypeInfo for PyFrozenSet

§

type AsRefTarget = PyFrozenSet

source§

const NAME: &'static str = "PyFrozenSet"

source§

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

source§

impl PyTypeInfo for PyFunction

§

type AsRefTarget = PyFunction

source§

const NAME: &'static str = "PyFunction"

source§

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

source§

impl PyTypeInfo for PyList

§

type AsRefTarget = PyList

source§

const NAME: &'static str = "PyList"

source§

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

source§

impl PyTypeInfo for PyLong

§

type AsRefTarget = PyLong

source§

const NAME: &'static str = "PyLong"

source§

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

source§

impl PyTypeInfo for PyModule

§

type AsRefTarget = PyModule

source§

const NAME: &'static str = "PyModule"

source§

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

source§

impl PyTypeInfo for PySet

§

type AsRefTarget = PySet

source§

const NAME: &'static str = "PySet"

source§

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

source§

impl PyTypeInfo for PySlice

§

type AsRefTarget = PySlice

source§

const NAME: &'static str = "PySlice"

source§

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

source§

impl PyTypeInfo for PyString

§

type AsRefTarget = PyString

source§

const NAME: &'static str = "PyString"

source§

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

source§

impl PyTypeInfo for PySuper

Available on non-PyPy only.
§

type AsRefTarget = PySuper

source§

const NAME: &'static str = "PySuper"

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 = "PyTime"

source§

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

source§

impl PyTypeInfo for PyTraceback

§

type AsRefTarget = PyTraceback

source§

const NAME: &'static str = "PyTraceback"

source§

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

source§

impl PyTypeInfo for PyTuple

§

type AsRefTarget = PyTuple

source§

const NAME: &'static str = "PyTuple"

source§

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

source§

impl PyTypeInfo for PyType

§

type AsRefTarget = PyType

source§

const NAME: &'static str = "PyType"

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 = "PyTzInfo"

source§

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