`ToPyObject` and `IntoPy` for `Borrowed`

This commit is contained in:
David Hewitt 2024-01-23 08:43:40 +00:00
parent eed196329d
commit 674f7282d8
1 changed files with 14 additions and 0 deletions

View File

@ -355,6 +355,20 @@ impl<T> Clone for Borrowed<'_, '_, T> {
impl<T> Copy for Borrowed<'_, '_, T> {}
impl<T> ToPyObject for Borrowed<'_, '_, T> {
/// Converts `Py` instance -> PyObject.
fn to_object(&self, py: Python<'_>) -> PyObject {
(*self).into_py(py)
}
}
impl<T> IntoPy<PyObject> 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.