From 007a191abfc609ff14632bc4664f0f6be641cb77 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 23 Jan 2025 16:23:57 +0000 Subject: [PATCH] Implement `AsPyPointer` for `Borrowed` This is already available in theory as the `as_ptr` method, but implementing the trait allows it to be used in a generic way. --- newsfragments/4868.added.md | 1 + src/instance.rs | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 newsfragments/4868.added.md diff --git a/newsfragments/4868.added.md b/newsfragments/4868.added.md new file mode 100644 index 00000000000..ef021debea4 --- /dev/null +++ b/newsfragments/4868.added.md @@ -0,0 +1 @@ +Implement [AsPyPointer] for [Borrowed] diff --git a/src/instance.rs b/src/instance.rs index 08a8779eadc..9e31da06689 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -839,6 +839,13 @@ impl IntoPy for Borrowed<'_, '_, T> { } } +unsafe impl AsPyPointer for Borrowed<'_, '_, T> { + #[inline] + fn as_ptr(&self) -> *mut ffi::PyObject { + Self::as_ptr(*self) + } +} + impl<'a, 'py, T> BoundObject<'py, T> for Borrowed<'a, 'py, T> { type Any = Borrowed<'a, 'py, PyAny>;