Skip to content

Instantly share code, notes, and snippets.

@earthnuker
Created July 8, 2019 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earthnuker/64c61994d80be668d2be55eeeb646dcd to your computer and use it in GitHub Desktop.
Save earthnuker/64c61994d80be668d2be55eeeb646dcd to your computer and use it in GitHub Desktop.
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