Crate rigetti_pyo3

Crate rigetti_pyo3 

Source
Expand description

Helpful macros and traits for creating a Python wrapper of a Rust library.

See Macros and Traits for the main items in this crate.

§Usage

See the examples directory in the source for example usage of a majority of the crate.

Alternatively, check the examples on the macros in this documentation.

Re-exports§

pub use num_complex;
pub use paste;
pub use pyo3;

Modules§

datetime
Defines DateTime to make converting between Python and time easier.

Macros§

create_init_submodule
Create a crate-private function init_submodule to set up this submodule and call the same function on child modules (which should also use this macro).
impl_as_mut_for_wrapper
Implement AsMut<T> for a Python wrapper around T.
impl_compare
Implement Python comparison for a given type. That type must implement PartialOrd.
impl_for_self
Implement ToPython<Self> for a given type.
impl_from_str
Implement FromStr for wrapper types whose inner type implements FromStr.
impl_hash
Implement __hash__ for types that implement Hash.
impl_parse
Implement a method parse for wrapper types that implement FromStr.
impl_repr
Implement __repr__ for wrapper types whose inner type implements Debug.
impl_str
Implement __str__ for wrapper types whose inner type implements Display.
private_impl_py_try_from
Implement PyTryFrom for a given Rust type.
private_impl_py_try_from_pyany
Generate PyTryFrom implementations for PyAny that require the PyAny to contain a specific Python type.
private_impl_py_try_from_with_pyany
Implement PyTryFrom<PyAny> for a given Rust type by delegating to its implementation for the given Python type.
private_impl_to_python_for
Implement ToPython once for the given Rust type. Will implement for a reference to the type if a lifetime is provided.
private_impl_to_python_pyany
Implement ToPython<Py<PyAny>> for a type using its implementation for ToPython<P> where P: ToPyObject.
private_impl_to_python_with_reference
Implement ToPython on the given Rust type and a reference to it.
private_intermediate_to_python
(Internal) Helper macro to implement chained conversion through intermediate types, where the type system cannot determine a path from the first to last item.
private_intermediate_try_from_python
(Internal) Helper macro to implement chained conversion through intermediate types, where the type system cannot determine a path from the last to first item.
private_py_try_from_py_pyany_inner
Provides a body for py_try_from, delegating to the implementation for the given Python type.
private_ultimate_type
(Internal) Helper macro to get the final type in a chain of conversions.
py_async
Convert a rust future into a Python awaitable using pyo3_asyncio::tokio::future_into_py
py_function_sync_async
Given a single implementation of an async function, create that function as private and two pyfunctions named after it that can be used to invoke either blocking or async variants of the same function.
py_sync
Spawn and block on a future using the pyo3 tokio runtime. Useful for returning a synchronous PyResult.
py_wrap_data_struct
Wraps a data struct and makes (some of) its fields available to Python.
py_wrap_error
Creates a new exception type and implements converting from the given Rust error to the new exception.
py_wrap_simple_enum
Wrap an enum containing only unit variants.
py_wrap_struct
Create a newtype wrapper for a Rust struct.
py_wrap_type
Create a Python wrapper around a Rust type.
py_wrap_union_enum
Create a newtype wrapper for a Rust enum with unique 1-tuple variants.
wrap_error
Wraps an external error type in a newtype struct so it can be used with py_wrap_error.

Traits§

PyTryFrom
Convert from a Python type to a Rust type.
PyWrapper
Implemented by wrapper types generated with py_wrap_* macros:
PyWrapperMut
Implemented by wrapper types containing the source type, generated with py_wrap_* macros:
ToPython
Convert from a Rust type into a Python type.
ToPythonError
Implemented by error types generated with py_wrap_error.