Replies: 3 comments 1 reply
-
Did you update your |
Beta Was this translation helpful? Give feedback.
0 replies
-
You mean like this? use pyo3::prelude::*;
#[pyclass]
struct Example {
#[pyo3(get, set)]
vector: Py<Vec<String>>,
}
#[pymethods]
impl Example {
#[new]
fn __new__(py: Python<'_>) -> PyResult<Self> {
Ok(Self {
vector: Py::new(py, vec![])?,
})
}
}
#[pymodule]
fn hej(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Example>()?;
Ok(())
} Then I get the following errors
And from here I do not know how to continue. :( |
Beta Was this translation helpful? Give feedback.
1 reply
-
You are right, I misunderstood her. Yes using Thanks so much! use pyo3::{prelude::*, types::PyList};
#[pyclass]
struct Example {
#[pyo3(get, set)]
vector: Py<PyList>,
}
#[pymethods]
impl Example {
#[new]
fn __new__(py: Python<'_>) -> Self {
Self {
vector: PyList::empty_bound(py).unbind(),
}
}
}
#[pymodule]
fn example(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Example>()?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have read the documentation at https://pyo3.rs/v0.22.2/faq#pyo3get-clones-my-field but I still can not figure out how to solve my issue. I have tried with this in
lib.rs
And this in python is what happens in python, which I guess is expected.
By reading the documentation I can see that I need to wrap my
vector
withPy<>
but then I do not know how to create my new function. I tried this but it does not work.Beta Was this translation helpful? Give feedback.
All reactions