Is there a way to return the same object from Rust side (singleton support)? #2382
Unanswered
lycantropos
asked this question in
Questions
Replies: 1 comment 6 replies
-
Maybe something like this? use pyo3::prelude::*;
#[pyclass]
struct Singleton { }
#[pymethods]
impl Singleton {
#[classattr]
#[allow(non_snake_case)]
fn VALUE() -> Py<Self> {
Python::with_gil(|py| Py::new(py, Singleton { })).unwrap()
}
} I don't think it's possible for |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Imagine I have some
Rust
enumeration that I want to export to Pythonand I also want it to be constructible in Python
finally module definition could be simply
The problem is that I want to return the same object so that Python's
is
operator works (like for Python'senum.Enum
s), but I getis there a way to do that?
Beta Was this translation helpful? Give feedback.
All reactions