Convert a Box<T>
into a PyClass
#2839
-
Say if I have this struct: #[pyclass]
#[derive(Clone)]
pub struct Leaf {
left: Option<Box<Leaf>>,
right: Option<Box<Leaf>>,
parent: Option<Box<Leaf>>,
} How can I access the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
If you want to hand out references to those Note that since using |
Beta Was this translation helpful? Give feedback.
If you want to hand out references to those
Leaf
objects to Python code, store them in thePy
smart pointer (i.e. on Python's heap with shared mutability using reference counting) instead of usingBox
.Note that since using
Py
implies shared ownership, you might need to use interior mutability of yourLeaf
structure is not immutable, e.g. usingOption<Py<PyCell<Leaf>>>
which would the Python-compatible equivalent ofOption<Rc<RefCell<Leaf>>
.