# pyo3::conversion::ToPyObject - Rust
Conversion trait that allows various objects to be converted into `PyObject`.
Keywords: rust, rustlang, rust-lang, ToPyObject

# Trait pyo3::conversion::ToPyObject [−] [src]

    pub trait ToPyObject {
        fn to_object(&self, py: Python<'_>) -> PyObject;
    }

Conversion trait that allows various objects to be converted into `PyObject`.

## Required methods

### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

Converts self into a Python object.

Loading content...

## Implementations on Foreign Types

### `impl<T: ?Sized + ToPyObject> ToPyObject for &T` [src]

Identity conversion: allows using existing `PyObject` instances where `T: ToPyObject` is expected.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for Option<T> where
T: ToPyObject,` [src]

`Option::Some<T>` is converted like `T`. `Option::None` is converted to Python `None`.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for ()` [src]

`()` is converted to Python `None`.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for bool` [src]

Converts a Rust `bool` to a Python `bool`.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<K, V, H> ToPyObject for HashMap<K, V, H> where
K: Hash + Eq + ToPyObject,
V: ToPyObject,
H: BuildHasher,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<K, V> ToPyObject for BTreeMap<K, V> where
K: Eq + ToPyObject,
V: ToPyObject,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for f64` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for f32` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for [T] where
T: ToPyObject,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for Vec<T> where
T: ToPyObject,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for i8` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for u8` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for i16` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for u16` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for i32` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for u32` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for i64` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for isize` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for usize` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for u64` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for i128` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for u128` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for HashSet<T> where
T: Hash + Eq + ToPyObject,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for BTreeSet<T> where
T: Hash + Eq + ToPyObject,` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for str` [src]

Converts a Rust `str` to a Python object. See `PyString::new` for details on the conversion.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<'a> ToPyObject for Cow<'a, str>` [src]

Converts a Rust `Cow<str>` to a Python object. See `PyString::new` for details on the conversion.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for String` [src]

Converts a Rust `String` to a Python object. See `PyString::new` for details on the conversion.

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for char` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject> ToPyObject for (A,)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject> ToPyObject for (A, B)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject> ToPyObject for (A, B, C)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject> ToPyObject for (A, B, C, D)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject> ToPyObject for (A, B, C, D, E)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject> ToPyObject for (A, B, C, D, E, F)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject> ToPyObject for (A, B, C, D, E, F, G)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject, H: ToPyObject> ToPyObject for (A, B, C, D, E, F, G, H)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject, H: ToPyObject, I: ToPyObject> ToPyObject for (A, B, C, D, E, F, G, H, I)` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

Loading content...

## Implementors

### `impl ToPyObject for CancelledError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for IncompleteReadError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for InvalidStateError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for LimitOverrunError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for QueueEmpty` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for QueueFull` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for TimeoutError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for gaierror` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for herror` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for timeout` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyArithmeticError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyAssertionError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyAttributeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBaseException` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBlockingIOError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBrokenPipeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBufferError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyChildProcessError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyConnectionAbortedError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyConnectionError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyConnectionRefusedError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyConnectionResetError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyEOFError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyEnvironmentError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyException` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFileExistsError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFileNotFoundError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFloatingPointError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyGeneratorExit` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyIOError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyImportError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyIndexError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyInterruptedError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyIsADirectoryError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyKeyError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyKeyboardInterrupt` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyLookupError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyMemoryError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyModuleNotFoundError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyNameError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyNotADirectoryError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyNotImplementedError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyOSError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyOverflowError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyPermissionError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyProcessLookupError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyRecursionError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyReferenceError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyRuntimeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyStopAsyncIteration` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyStopIteration` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySyntaxError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySystemError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySystemExit` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyTimeoutError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyTypeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyUnboundLocalError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyUnicodeDecodeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyUnicodeEncodeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyUnicodeError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyUnicodeTranslateError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyValueError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyZeroDivisionError` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PanicException` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyAny` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyErr` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyModule` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBool` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyByteArray` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyBytes` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyCFunction` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyComplex` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyDate` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyDateTime` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyDelta` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyDict` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFloat` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFrozenSet` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyFunction` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyIterator` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyList` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyLong` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySequence` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySet` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySlice` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PySliceIndices` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyString` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyTime` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyTuple` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyType` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl ToPyObject for PyTzInfo` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

### `impl<T> ToPyObject for Py<T>` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

Converts `Py` instance -> PyObject.

### `impl<T: PyClass> ToPyObject for &PyCell<T>` [src]

#### `fn to_object(&self, py: Python<'_>) -> PyObject` [src]

Loading content...