How to use Vec<MyPyClass> as parameter a of pyfunction? #2103
-
|
Hi there, I have a pyclass as below: #[pyclass]
pub struct Foo {
values: Vec<bool>,
}and a function as below: #[pyfunction]
pub fn bar(conditions: Vec<&Foo>) -> BooleanList {
...
}The codes above cannot run, because of I tried to implement the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Have you tried Alternatively you can pass by value, e.g. |
Beta Was this translation helpful? Give feedback.
Have you tried
Vec<Py<Foo>>?Py<T>is a pointer to a pyclassTmanaged by the Python heap. If the Python code passes e.g. alistofFooto you, then this list will actually contain pointers toFooinstance on the heap.Alternatively you can pass by value, e.g.
Vec<Foo>if that makes sense w.r.t. the semantics ofFoo, e.g. I think this requiresFoo: Clone, i.e. adding#[derive(Clone)]tostruct Foo.