My code below.
#rust_lib/src/lib.rs
use pyo3::prelude::*;
use pyo3::types::{PyDate};
use relativedelta::RelativeDelta;
#[pyfunction]
fn create_date(_py: Python) -> PyResult<&PyDate> {
let date = PyDate::new(_py, 2022, 3, 1);
println!("rust date is {:?}", &date);
date
}
#[pymodule]
fn rust(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(create_date, m)?)?;
Ok(())
}
#python.py
import rust_lib
print('python date is', rust_lib.create_date())
When I run this I get this compiler error (
error[E0369]: cannot add `RelativeDelta` to `Result<&PyDate, PyErr>`
--> src/lib.rs:40:37
|
40 | let changed_date:&PyDate = date + months12;
| ---- ^ -------- RelativeDelta
| |
| Result<&PyDate, PyErr>
How do I fix this? The code runs if I remove the 2 relative delta lines. Do I need to unpack the PyDate and PyErr from the PyResult?