Created
July 8, 2019 23:45
-
-
Save earthnuker/64c61994d80be668d2be55eeeb646dcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use pyo3::prelude::*; | |
#[allow(dead_code)] | |
#[pyclass] | |
pub struct State { | |
pub x: usize, | |
pub y: usize, | |
pub z: usize, | |
} | |
#[pymodule] | |
fn py_test(py: Python, m: &PyModule) -> PyResult<()> { | |
m.add_class::<State>()?; | |
#[pyfn(m, "sum_as_string")] | |
fn sum_as_string(py: Python, a: usize, b: usize, callback: PyObject) -> PyResult<PyObject> { | |
println!("Hello from Rust!"); | |
let state = Py::new( | |
py, | |
State { | |
x: a, | |
y: b, | |
z: a + b, | |
}, | |
) | |
.unwrap(); | |
callback.call(py, (state,), None) | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment