Skip to main content

upgrade_py_weakref

Function upgrade_py_weakref 

Source
pub fn upgrade_py_weakref(
    py_self: Option<&Py<PyWeakrefReference>>,
    owner: &dyn Display,
) -> PyResult<Option<Py<PyAny>>>
Expand description

Upgrades the weak reference a Rust object keeps to its Python wrapper.

Returns Ok(None) when no wrapper was ever attached, which is the case for a purely Rust construction. owner names the Rust object in the error message.

ยงErrors

Returns an error if a wrapper was attached but has since been collected. Callers propagate this rather than skipping a required callback, because a live wrapper is an ownership invariant of the caller rather than an optional extra.