-
I have a question. I'm writing an algorithm that I want to use only in rust but this algo needs some parameters as result of an optimisation. Since there is a lack of optimisation library in rust (with respect to python) I need to expose some struct in python and some methods with the objective function. My rust struct impl Foo { In the python object I need only a concrete implementation of I and S, say i64 and String. How can I define a struct to wraps Foo into a Python object without changing the rust code (that I need to use after the optimisation)? And I need to export the optimisation function too. I made a copy of the rust Foo with pyclass and it works but it's a code duplication and I want to avoid if possible. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Is this what you want? use pyo3::prelude::*;
pub struct Foo<I, S> {
a: I,
b: S,
}
#[pyclass]
pub struct PyFoo {
inner: Foo<i64, String>,
} |
Beta Was this translation helpful? Give feedback.
Is this what you want?
https://www.rustexplorer.com/b/z4p7n1