0

I've been working on integrating rust code into python using PyO3 and Maturin. I've successfully written my Rust class and gotten most of the functionality to work, however I haven't been able to successfully deepcopy the object. I've tried workarounds using wrapper classes and custom defined deepcopy and getattr/setattr to not much avail, since it seems that the rust functions aren't pickleable. The Rust class is included in a standard #[pymodule], and tagged as a standard #[pyclass]. Has anyone encountered this issue before, and is there any way around it? Or should I just avoid deepcopying in my python code.

wfjohns1
  • 31
  • 2

1 Answers1

0

You need to define a __deepcopy__() method, like:

fn __deepcopy__(&self, _memo: &PyDict) -> Self {
    self.clone()
}

As explained in the copy module documentation.

Pickling is more involved, but see PyO3 issue #100.

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77