| 564 |
564 |
| 565 fn dual_origin(&self) -> <Self::DualSpace as AXPY>::Owned { |
565 fn dual_origin(&self) -> <Self::DualSpace as AXPY>::Owned { |
| 566 Pair(self.0.dual_origin(), self.1.dual_origin()) |
566 Pair(self.0.dual_origin(), self.1.dual_origin()) |
| 567 } |
567 } |
| 568 } |
568 } |
| |
569 |
| |
570 #[cfg(feature = "pyo3")] |
| |
571 mod python { |
| |
572 use super::Pair; |
| |
573 use pyo3::conversion::FromPyObject; |
| |
574 use pyo3::types::{PyAny, PyTuple}; |
| |
575 use pyo3::{Bound, IntoPyObject, PyErr, PyResult, Python}; |
| |
576 |
| |
577 impl<'py, A, B> IntoPyObject<'py> for Pair<A, B> |
| |
578 where |
| |
579 A: IntoPyObject<'py>, |
| |
580 B: IntoPyObject<'py>, |
| |
581 { |
| |
582 type Target = PyTuple; |
| |
583 type Error = PyErr; |
| |
584 type Output = Bound<'py, Self::Target>; |
| |
585 |
| |
586 fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { |
| |
587 (self.0, self.1).into_pyobject(py) |
| |
588 } |
| |
589 } |
| |
590 |
| |
591 impl<'a, 'py, A, B> IntoPyObject<'py> for &'a mut Pair<A, B> |
| |
592 where |
| |
593 &'a mut A: IntoPyObject<'py>, |
| |
594 &'a mut B: IntoPyObject<'py>, |
| |
595 { |
| |
596 type Target = PyTuple; |
| |
597 type Error = PyErr; |
| |
598 type Output = Bound<'py, Self::Target>; |
| |
599 |
| |
600 fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { |
| |
601 (&mut self.0, &mut self.1).into_pyobject(py) |
| |
602 } |
| |
603 } |
| |
604 |
| |
605 impl<'a, 'py, A, B> IntoPyObject<'py> for &'a Pair<A, B> |
| |
606 where |
| |
607 &'a A: IntoPyObject<'py>, |
| |
608 &'a B: IntoPyObject<'py>, |
| |
609 { |
| |
610 type Target = PyTuple; |
| |
611 type Error = PyErr; |
| |
612 type Output = Bound<'py, Self::Target>; |
| |
613 |
| |
614 fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { |
| |
615 (&self.0, &self.1).into_pyobject(py) |
| |
616 } |
| |
617 } |
| |
618 |
| |
619 impl<'py, A, B> FromPyObject<'py> for Pair<A, B> |
| |
620 where |
| |
621 A: Clone + FromPyObject<'py>, |
| |
622 B: Clone + FromPyObject<'py>, |
| |
623 { |
| |
624 fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> { |
| |
625 FromPyObject::extract_bound(ob).map(|(a, b)| Pair(a, b)) |
| |
626 } |
| |
627 } |
| |
628 } |