Trait pyo3::conversion::ToBorrowedObject
source · [−]pub trait ToBorrowedObject: ToPyObject {
fn with_borrowed_ptr<F, R>(&self, py: Python<'_>, f: F) -> R
where
F: FnOnce(*mut PyObject) -> R,
{ ... }
}
Expand description
This trait has two implementations: The slow one is implemented for all ToPyObject and creates a new object using ToPyObject::to_object, while the fast one is only implemented for AsPyPointer (we know that every AsPyPointer is also ToPyObject) and uses AsPyPointer::as_ptr()
Provided Methods
Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object.
May be more efficient than to_object
because it does not need
to touch any reference counts when the input object already is a Python object.