Skip to content

Instantly share code, notes, and snippets.

@ognis1205
Created June 13, 2023 13:06
Show Gist options
  • Save ognis1205/87da134b80cf1f9b64e2725c32c5f8af to your computer and use it in GitHub Desktop.
Save ognis1205/87da134b80cf1f9b64e2725c32c5f8af to your computer and use it in GitHub Desktop.
use pyo3::prelude::*;
/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
/// A Python module implemented in Rust.
#[pymodule]
fn my_first_pyo3(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment