-
When a struct implements a custom trait, how can i use the functions defined by the trait in Python? Here is a minimal example: trait Bar {
fn bar(&self) -> i32;
fn barbar(&self) -> i32 {
self.bar() * 2
}
}
#[pyclass]
pub struct Foo {
pub x: i32,
}
#[pymethods]
impl Foo {
#[new]
pub fn new(x: i32) -> Self {
Self { x }
}
}
impl Bar for Foo {
fn bar(&self) -> i32 {
self.x
}
} Is it possible to use the |
Beta Was this translation helpful? Give feedback.
Answered by
mejrs
Oct 9, 2023
Replies: 1 comment
-
No, you have to define methods that forward to the trait. See https://pyo3.rs/v0.19.2/trait_bounds |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
azazdeaz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, you have to define methods that forward to the trait. See https://pyo3.rs/v0.19.2/trait_bounds