Skip to content

Commit

Permalink
add detailed docs to ref_from_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Feb 16, 2024
1 parent f6e3336 commit ebfc2c3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ impl<'py> Bound<'py, PyAny> {
Py::from_owned_ptr_or_err(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
}

/// This slightly strange method is used to obtain `&Bound<PyAny>` from a pointer in macro code
/// where we need to constrain the lifetime `'a` safely.
///
/// Note that `'py` is required to outlive `'a` implicitly by the nature of the fact that
/// `&'a Bound<'py>` means that `Bound<'py>` exists for at least the lifetime `'a`.
///
/// # Safety
/// - `ptr` must be a valid pointer to a Python object for the lifetime `'a`. The `ptr` can
/// be either a borrowed reference or an owned reference, it does not matter, as this is
/// just `&Bound` there will never be any ownership transfer.
#[inline]
pub(crate) unsafe fn ref_from_ptr<'a>(
_py: Python<'py>,
Expand Down

0 comments on commit ebfc2c3

Please sign in to comment.