Hi community,
I have a use case where I am defining a pyclass and I need to have a static method in that class that takes the same pyclass along with another pyclass as parameters and does some computation on them.
When I try the below code, I get "FromPyObject" not implemented for PyG1 and PyG2, how do I go about fixing this, any help is appreciated.
```rust
struct PyG1 {
g1 : G1
}
impl PyG1 {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()>{
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let g = G1::rand(&mut rng);
obj.init(|t| PyG1{
g1: g,
})
}
#[staticmethod]
fn py_pairing(g1: PyG1, g2: PyG2) -> PyResult<()> {
Ok(())
}
}
struct PyG2 {
g2 : G2
}
impl PyG2 {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()>{
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let g = G2::rand(&mut rng);
obj.init(|t| PyG2{
g2: g,
})
}
}
@hybridNeo You have some formatting issues in your post. Surround your code with
~~~markdown
// Your code
~~~
in order to make it easier to understand.
Since python is call-by-reference only, you can only get references in function calls for your custom types. fn py_pairing(g1: &PyG1, g2: &PyG2) -> PyResult<()> does the trick.
Most helpful comment
Since python is call-by-reference only, you can only get references in function calls for your custom types.
fn py_pairing(g1: &PyG1, g2: &PyG2) -> PyResult<()>does the trick.