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 { ... }
}
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§
Sourcetype AsRefSource: HasPyGilRef<AsRefTarget = Self>
type AsRefSource: HasPyGilRef<AsRefTarget = Self>
The form of this which is stored inside a Py<T>
smart pointer.
Provided Methods§
Sourcefn as_borrowed(&self) -> Borrowed<'_, '_, Self::AsRefSource>
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.
Sourceunsafe fn unchecked_downcast(obj: &PyAny) -> &Self
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
impl PyNativeType for CancelledError
type AsRefSource = CancelledError
Source§impl PyNativeType for InvalidStateError
impl PyNativeType for InvalidStateError
Source§impl PyNativeType for LimitOverrunError
impl PyNativeType for LimitOverrunError
Source§impl PyNativeType for QueueEmpty
impl PyNativeType for QueueEmpty
type AsRefSource = QueueEmpty
Source§impl PyNativeType for QueueFull
impl PyNativeType for QueueFull
type AsRefSource = QueueFull
Source§impl PyNativeType for TimeoutError
impl PyNativeType for TimeoutError
type AsRefSource = TimeoutError
Source§impl PyNativeType for gaierror
impl PyNativeType for gaierror
type AsRefSource = gaierror
Source§impl PyNativeType for herror
impl PyNativeType for herror
type AsRefSource = herror
Source§impl PyNativeType for timeout
impl PyNativeType for timeout
type AsRefSource = timeout
Source§impl PyNativeType for PyArithmeticError
impl PyNativeType for PyArithmeticError
Source§impl PyNativeType for PyAssertionError
impl PyNativeType for PyAssertionError
Source§impl PyNativeType for PyAttributeError
impl PyNativeType for PyAttributeError
Source§impl PyNativeType for PyBaseException
impl PyNativeType for PyBaseException
Source§impl PyNativeType for PyBlockingIOError
impl PyNativeType for PyBlockingIOError
Source§impl PyNativeType for PyBrokenPipeError
impl PyNativeType for PyBrokenPipeError
Source§impl PyNativeType for PyBufferError
impl PyNativeType for PyBufferError
type AsRefSource = PyBufferError
Source§impl PyNativeType for PyBytesWarning
impl PyNativeType for PyBytesWarning
type AsRefSource = PyBytesWarning
Source§impl PyNativeType for PyConnectionError
impl PyNativeType for PyConnectionError
Source§impl PyNativeType for PyEOFError
impl PyNativeType for PyEOFError
type AsRefSource = PyEOFError
Source§impl PyNativeType for PyEncodingWarning
impl PyNativeType for PyEncodingWarning
Source§impl PyNativeType for PyException
impl PyNativeType for PyException
type AsRefSource = PyException
Source§impl PyNativeType for PyFileExistsError
impl PyNativeType for PyFileExistsError
Source§impl PyNativeType for PyFutureWarning
impl PyNativeType for PyFutureWarning
Source§impl PyNativeType for PyGeneratorExit
impl PyNativeType for PyGeneratorExit
Source§impl PyNativeType for PyIOError
impl PyNativeType for PyIOError
type AsRefSource = PyIOError
Source§impl PyNativeType for PyImportError
impl PyNativeType for PyImportError
type AsRefSource = PyImportError
Source§impl PyNativeType for PyImportWarning
impl PyNativeType for PyImportWarning
Source§impl PyNativeType for PyIndexError
impl PyNativeType for PyIndexError
type AsRefSource = PyIndexError
Source§impl PyNativeType for PyKeyError
impl PyNativeType for PyKeyError
type AsRefSource = PyKeyError
Source§impl PyNativeType for PyLookupError
impl PyNativeType for PyLookupError
type AsRefSource = PyLookupError
Source§impl PyNativeType for PyMemoryError
impl PyNativeType for PyMemoryError
type AsRefSource = PyMemoryError
Source§impl PyNativeType for PyNameError
impl PyNativeType for PyNameError
type AsRefSource = PyNameError
Source§impl PyNativeType for PyOSError
impl PyNativeType for PyOSError
type AsRefSource = PyOSError
Source§impl PyNativeType for PyOverflowError
impl PyNativeType for PyOverflowError
Source§impl PyNativeType for PyPermissionError
impl PyNativeType for PyPermissionError
Source§impl PyNativeType for PyRecursionError
impl PyNativeType for PyRecursionError
Source§impl PyNativeType for PyReferenceError
impl PyNativeType for PyReferenceError
Source§impl PyNativeType for PyResourceWarning
impl PyNativeType for PyResourceWarning
Source§impl PyNativeType for PyRuntimeError
impl PyNativeType for PyRuntimeError
type AsRefSource = PyRuntimeError
Source§impl PyNativeType for PyRuntimeWarning
impl PyNativeType for PyRuntimeWarning
Source§impl PyNativeType for PyStopIteration
impl PyNativeType for PyStopIteration
Source§impl PyNativeType for PySyntaxError
impl PyNativeType for PySyntaxError
type AsRefSource = PySyntaxError
Source§impl PyNativeType for PySyntaxWarning
impl PyNativeType for PySyntaxWarning
Source§impl PyNativeType for PySystemError
impl PyNativeType for PySystemError
type AsRefSource = PySystemError
Source§impl PyNativeType for PySystemExit
impl PyNativeType for PySystemExit
type AsRefSource = PySystemExit
Source§impl PyNativeType for PyTimeoutError
impl PyNativeType for PyTimeoutError
type AsRefSource = PyTimeoutError
Source§impl PyNativeType for PyTypeError
impl PyNativeType for PyTypeError
type AsRefSource = PyTypeError
Source§impl PyNativeType for PyUnicodeError
impl PyNativeType for PyUnicodeError
type AsRefSource = PyUnicodeError
Source§impl PyNativeType for PyUnicodeWarning
impl PyNativeType for PyUnicodeWarning
Source§impl PyNativeType for PyUserWarning
impl PyNativeType for PyUserWarning
type AsRefSource = PyUserWarning
Source§impl PyNativeType for PyValueError
impl PyNativeType for PyValueError
type AsRefSource = PyValueError
Source§impl PyNativeType for PyWarning
impl PyNativeType for PyWarning
type AsRefSource = PyWarning
Source§impl PyNativeType for PanicException
impl PyNativeType for PanicException
type AsRefSource = PanicException
Source§impl PyNativeType for PyAny
impl PyNativeType for PyAny
type AsRefSource = PyAny
Source§impl PyNativeType for PyBool
impl PyNativeType for PyBool
type AsRefSource = PyBool
Source§impl PyNativeType for PyByteArray
impl PyNativeType for PyByteArray
type AsRefSource = PyByteArray
Source§impl PyNativeType for PyBytes
impl PyNativeType for PyBytes
type AsRefSource = PyBytes
Source§impl PyNativeType for PyCFunction
impl PyNativeType for PyCFunction
type AsRefSource = PyCFunction
Source§impl PyNativeType for PyCapsule
impl PyNativeType for PyCapsule
type AsRefSource = PyCapsule
Source§impl PyNativeType for PyCode
Available on non-Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.
impl PyNativeType for PyCode
Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.type AsRefSource = PyCode
Source§impl PyNativeType for PyComplex
impl PyNativeType for PyComplex
type AsRefSource = PyComplex
Source§impl PyNativeType for PyDate
Available on non-Py_LIMITED_API
only.
impl PyNativeType for PyDate
Py_LIMITED_API
only.type AsRefSource = PyDate
Source§impl PyNativeType for PyDateTime
Available on non-Py_LIMITED_API
only.
impl PyNativeType for PyDateTime
Py_LIMITED_API
only.type AsRefSource = PyDateTime
Source§impl PyNativeType for PyDelta
Available on non-Py_LIMITED_API
only.
impl PyNativeType for PyDelta
Py_LIMITED_API
only.type AsRefSource = PyDelta
Source§impl PyNativeType for PyDict
impl PyNativeType for PyDict
type AsRefSource = PyDict
Source§impl PyNativeType for PyDictItems
impl PyNativeType for PyDictItems
type AsRefSource = PyDictItems
Source§impl PyNativeType for PyDictKeys
impl PyNativeType for PyDictKeys
type AsRefSource = PyDictKeys
Source§impl PyNativeType for PyDictValues
impl PyNativeType for PyDictValues
type AsRefSource = PyDictValues
Source§impl PyNativeType for PyEllipsis
impl PyNativeType for PyEllipsis
type AsRefSource = PyEllipsis
Source§impl PyNativeType for PyFloat
impl PyNativeType for PyFloat
type AsRefSource = PyFloat
Source§impl PyNativeType for PyFrame
Available on non-Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.
impl PyNativeType for PyFrame
Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.type AsRefSource = PyFrame
Source§impl PyNativeType for PyFrozenSet
impl PyNativeType for PyFrozenSet
type AsRefSource = PyFrozenSet
Source§impl PyNativeType for PyFunction
impl PyNativeType for PyFunction
type AsRefSource = PyFunction
Source§impl PyNativeType for PyIterator
impl PyNativeType for PyIterator
type AsRefSource = PyIterator
Source§impl PyNativeType for PyList
impl PyNativeType for PyList
type AsRefSource = PyList
Source§impl PyNativeType for PyLong
impl PyNativeType for PyLong
type AsRefSource = PyLong
Source§impl PyNativeType for PyMapping
impl PyNativeType for PyMapping
type AsRefSource = PyMapping
Source§impl PyNativeType for PyMemoryView
impl PyNativeType for PyMemoryView
type AsRefSource = PyMemoryView
Source§impl PyNativeType for PyModule
impl PyNativeType for PyModule
type AsRefSource = PyModule
Source§impl PyNativeType for PyNone
impl PyNativeType for PyNone
type AsRefSource = PyNone
Source§impl PyNativeType for PyNotImplemented
impl PyNativeType for PyNotImplemented
Source§impl PyNativeType for PySequence
impl PyNativeType for PySequence
type AsRefSource = PySequence
Source§impl PyNativeType for PySet
impl PyNativeType for PySet
type AsRefSource = PySet
Source§impl PyNativeType for PySlice
impl PyNativeType for PySlice
type AsRefSource = PySlice
Source§impl PyNativeType for PyString
impl PyNativeType for PyString
type AsRefSource = PyString
Source§impl PyNativeType for PySuper
Available on neither PyPy
nor GraalPy
.
impl PyNativeType for PySuper
PyPy
nor GraalPy
.type AsRefSource = PySuper
Source§impl PyNativeType for PyTime
Available on non-Py_LIMITED_API
only.
impl PyNativeType for PyTime
Py_LIMITED_API
only.type AsRefSource = PyTime
Source§impl PyNativeType for PyTraceback
impl PyNativeType for PyTraceback
type AsRefSource = PyTraceback
Source§impl PyNativeType for PyTuple
impl PyNativeType for PyTuple
type AsRefSource = PyTuple
Source§impl PyNativeType for PyType
impl PyNativeType for PyType
type AsRefSource = PyType
Source§impl PyNativeType for PyTzInfo
Available on non-Py_LIMITED_API
only.
impl PyNativeType for PyTzInfo
Py_LIMITED_API
only.