Hi,I have this problem. I created two stuctures in RUST where one contains required fields and the other contains optional fields. The compilation went fine, in Python I imported the library but when I want to create an object in Python, that will contain optional fields I get an error.
#[pyclass(name = "class_1")]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PyClassMandatory {
#[pyo3(get, set)]
field1: String,
#[pyo3(get, set)]
field2: String,
#[pyo3(get, set)]
py_class_non_mandatory: PyClassNonMandatory
}
#[pyclass(name = "class_1")]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PyClassNonMandatory {
#[pyo3(get, set)]
field3: Option<String>,
#[pyo3(get, set)]
field4: Option<String>
}
impl Default for PyClassNonMandatory {
fn default() -> PyClassNonMandatory {
PyClassNonMandatory {
field3: Default::default(),
field4: Default::default()
}
}
}
#[pymethods]
impl PyClassMandatory {
#[new]
fn __new__(field1: String, field2: String) -> Self {
PyClassMandatory {
field1,
field2,
py_class_non_mandatory: Default::default()
}
}