pyo3

Trait PyNativeType

Source
pub unsafe trait PyNativeType: Sized {
    type AsRefSource: HasPyGilRef<AsRefTarget = Self>;

    // Provided methods
    fn as_borrowed(&self) -> Borrowed<'_, '_, Self::AsRefSource> { ... }
    fn py(&self) -> Python<'_> { ... }
    unsafe fn unchecked_downcast(obj: &PyAny) -> &Self { ... }
}
Available on crate feature gil-refs only.
Expand description

Types that are built into the Python interpreter.

PyO3 is designed in a way that all references to those types are bound to the GIL, which is why you can get a token from all references of those types.

§Safety

This trait must only be implemented for types which cannot be accessed without the GIL.

Required Associated Types§

Source

type AsRefSource: HasPyGilRef<AsRefTarget = Self>

The form of this which is stored inside a Py<T> smart pointer.

Provided Methods§

Source

fn as_borrowed(&self) -> Borrowed<'_, '_, Self::AsRefSource>

Cast &self to a Borrowed smart pointer.

Borrowed<T> implements Deref<Target=Bound<T>>, so can also be used in locations where Bound<T> is expected.

This is available as a migration tool to adjust code from the deprecated “GIL Refs” API to the Bound smart pointer API.

Source

fn py(&self) -> Python<'_>

Returns a GIL marker constrained to the lifetime of this type.

Source

unsafe fn unchecked_downcast(obj: &PyAny) -> &Self

Cast &PyAny to &Self without no type checking.

§Safety

obj must have the same layout as *const ffi::PyObject and must be an instance of a type corresponding to Self.

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 PyNativeType for CancelledError

Source§

impl PyNativeType for IncompleteReadError

Source§

impl PyNativeType for InvalidStateError

Source§

impl PyNativeType for LimitOverrunError

Source§

impl PyNativeType for QueueEmpty

Source§

impl PyNativeType for QueueFull

Source§

impl PyNativeType for TimeoutError

Source§

impl PyNativeType for gaierror

Source§

impl PyNativeType for herror

Source§

impl PyNativeType for timeout

Source§

impl PyNativeType for PyArithmeticError

Source§

impl PyNativeType for PyAssertionError

Source§

impl PyNativeType for PyAttributeError

Source§

impl PyNativeType for PyBaseException

Source§

impl PyNativeType for PyBlockingIOError

Source§

impl PyNativeType for PyBrokenPipeError

Source§

impl PyNativeType for PyBufferError

Source§

impl PyNativeType for PyBytesWarning

Source§

impl PyNativeType for PyChildProcessError

Source§

impl PyNativeType for PyConnectionAbortedError

Source§

impl PyNativeType for PyConnectionError

Source§

impl PyNativeType for PyConnectionRefusedError

Source§

impl PyNativeType for PyConnectionResetError

Source§

impl PyNativeType for PyDeprecationWarning

Source§

impl PyNativeType for PyEOFError

Source§

impl PyNativeType for PyEncodingWarning

Source§

impl PyNativeType for PyEnvironmentError

Source§

impl PyNativeType for PyException

Source§

impl PyNativeType for PyFileExistsError

Source§

impl PyNativeType for PyFileNotFoundError

Source§

impl PyNativeType for PyFloatingPointError

Source§

impl PyNativeType for PyFutureWarning

Source§

impl PyNativeType for PyGeneratorExit

Source§

impl PyNativeType for PyIOError

Source§

impl PyNativeType for PyImportError

Source§

impl PyNativeType for PyImportWarning

Source§

impl PyNativeType for PyIndexError

Source§

impl PyNativeType for PyInterruptedError

Source§

impl PyNativeType for PyIsADirectoryError

Source§

impl PyNativeType for PyKeyError

Source§

impl PyNativeType for PyKeyboardInterrupt

Source§

impl PyNativeType for PyLookupError

Source§

impl PyNativeType for PyMemoryError

Source§

impl PyNativeType for PyModuleNotFoundError

Source§

impl PyNativeType for PyNameError

Source§

impl PyNativeType for PyNotADirectoryError

Source§

impl PyNativeType for PyNotImplementedError

Source§

impl PyNativeType for PyOSError

Source§

impl PyNativeType for PyOverflowError

Source§

impl PyNativeType for PyPendingDeprecationWarning

Source§

impl PyNativeType for PyPermissionError

Source§

impl PyNativeType for PyProcessLookupError

Source§

impl PyNativeType for PyRecursionError

Source§

impl PyNativeType for PyReferenceError

Source§

impl PyNativeType for PyResourceWarning

Source§

impl PyNativeType for PyRuntimeError

Source§

impl PyNativeType for PyRuntimeWarning

Source§

impl PyNativeType for PyStopAsyncIteration

Source§

impl PyNativeType for PyStopIteration

Source§

impl PyNativeType for PySyntaxError

Source§

impl PyNativeType for PySyntaxWarning

Source§

impl PyNativeType for PySystemError

Source§

impl PyNativeType for PySystemExit

Source§

impl PyNativeType for PyTimeoutError

Source§

impl PyNativeType for PyTypeError

Source§

impl PyNativeType for PyUnboundLocalError

Source§

impl PyNativeType for PyUnicodeDecodeError

Source§

impl PyNativeType for PyUnicodeEncodeError

Source§

impl PyNativeType for PyUnicodeError

Source§

impl PyNativeType for PyUnicodeTranslateError

Source§

impl PyNativeType for PyUnicodeWarning

Source§

impl PyNativeType for PyUserWarning

Source§

impl PyNativeType for PyValueError

Source§

impl PyNativeType for PyWarning

Source§

impl PyNativeType for PyZeroDivisionError

Source§

impl PyNativeType for PanicException

Source§

impl PyNativeType for PyAny

Source§

impl PyNativeType for PyBool

Source§

impl PyNativeType for PyByteArray

Source§

impl PyNativeType for PyBytes

Source§

impl PyNativeType for PyCFunction

Source§

impl PyNativeType for PyCapsule

Source§

impl PyNativeType for PyCode

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

impl PyNativeType for PyComplex

Source§

impl PyNativeType for PyDate

Available on non-Py_LIMITED_API only.
Source§

impl PyNativeType for PyDateTime

Available on non-Py_LIMITED_API only.
Source§

impl PyNativeType for PyDelta

Available on non-Py_LIMITED_API only.
Source§

impl PyNativeType for PyDict

Source§

impl PyNativeType for PyDictItems

Source§

impl PyNativeType for PyDictKeys

Source§

impl PyNativeType for PyDictValues

Source§

impl PyNativeType for PyEllipsis

Source§

impl PyNativeType for PyFloat

Source§

impl PyNativeType for PyFrame

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

impl PyNativeType for PyFrozenSet

Source§

impl PyNativeType for PyFunction

Source§

impl PyNativeType for PyIterator

Source§

impl PyNativeType for PyList

Source§

impl PyNativeType for PyLong

Source§

impl PyNativeType for PyMapping

Source§

impl PyNativeType for PyMemoryView

Source§

impl PyNativeType for PyModule

Source§

impl PyNativeType for PyNone

Source§

impl PyNativeType for PyNotImplemented

Source§

impl PyNativeType for PySequence

Source§

impl PyNativeType for PySet

Source§

impl PyNativeType for PySlice

Source§

impl PyNativeType for PyString

Source§

impl PyNativeType for PySuper

Available on neither PyPy nor GraalPy.
Source§

impl PyNativeType for PyTime

Available on non-Py_LIMITED_API only.
Source§

impl PyNativeType for PyTraceback

Source§

impl PyNativeType for PyTuple

Source§

impl PyNativeType for PyType

Source§

impl PyNativeType for PyTzInfo

Available on non-Py_LIMITED_API only.
Source§

impl PyNativeType for PyWeakref

Source§

impl PyNativeType for PyWeakrefProxy

Source§

impl PyNativeType for PyWeakrefReference

Source§

impl<T: PyClass> PyNativeType for PyCell<T>