use std::ffi::c_double;
use num_complex::Complex;
use num_traits::{Float, FloatConst};
use pyo3::IntoPy;
use pyo3::{types::PyComplex, Py, PyAny, PyResult, Python};
use crate::{impl_for_self, ToPython};
impl_for_self!(Py<PyComplex>);
#[cfg(feature = "complex")]
impl<'a, F> ToPython<Py<PyComplex>> for &'a Complex<F>
where
F: Copy + Float + FloatConst + Into<c_double>,
{
fn to_python(&self, py: Python) -> PyResult<Py<PyComplex>> {
Ok(PyComplex::from_complex(py, **self).into_py(py))
}
}
#[cfg(feature = "complex")]
impl<F> ToPython<Py<PyComplex>> for Complex<F>
where
F: Copy + Float + FloatConst + Into<c_double>,
{
fn to_python(&self, py: Python) -> PyResult<Py<PyComplex>> {
<&Self as ToPython<Py<PyComplex>>>::to_python(&self, py)
}
}
#[cfg(feature = "complex")]
impl<'a, F> ToPython<Py<PyAny>> for &'a Complex<F>
where
F: Copy + Float + FloatConst + Into<c_double>,
{
fn to_python(&self, py: Python) -> PyResult<Py<PyAny>> {
Ok(PyComplex::from_complex(py, **self).into_py(py))
}
}
#[cfg(feature = "complex")]
impl<F> ToPython<Py<PyAny>> for Complex<F>
where
F: Copy + Float + FloatConst + Into<c_double>,
{
fn to_python(&self, py: Python) -> PyResult<Py<PyAny>> {
<&Self as ToPython<Py<PyAny>>>::to_python(&self, py)
}
}