From 674f7282d800d32a06e2a230af820fe2f26c0f22 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 23 Jan 2024 08:43:40 +0000 Subject: [PATCH] `ToPyObject` and `IntoPy` for `Borrowed` --- src/instance.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/instance.rs b/src/instance.rs index 5779e9ad..4d449993 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -355,6 +355,20 @@ impl Clone for Borrowed<'_, '_, T> { impl Copy for Borrowed<'_, '_, T> {} +impl ToPyObject for Borrowed<'_, '_, T> { + /// Converts `Py` instance -> PyObject. + fn to_object(&self, py: Python<'_>) -> PyObject { + (*self).into_py(py) + } +} + +impl IntoPy for Borrowed<'_, '_, T> { + /// Converts `Py` instance -> PyObject. + fn into_py(self, py: Python<'_>) -> PyObject { + self.to_owned().into_py(py) + } +} + /// A GIL-independent reference to an object allocated on the Python heap. /// /// This type does not auto-dereference to the inner object because you must prove you hold the GIL to access it.