We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 234227a commit 6caa75bCopy full SHA for 6caa75b
examples/simple/src/lib.rs
@@ -16,9 +16,9 @@ use pyo3::{
16
#[pymodule]
17
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
18
// example using generic PyObject
19
- fn head(x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
+ fn head(py: Python<'_>, x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
20
x.get(0)
21
- .cloned()
+ .map(|obj| obj.clone_ref(py))
22
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
23
}
24
@@ -49,7 +49,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
49
#[pyfn(m)]
50
#[pyo3(name = "head")]
51
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, PyObject>) -> PyResult<PyObject> {
52
- head(x.as_array())
+ head(x.py(), x.as_array())
53
54
55
// wrapper of `axpy`
0 commit comments