Created
May 1, 2019 17:02
-
-
Save chhetripradeep/3c64187f83f598551b0bb05649553b91 to your computer and use it in GitHub Desktop.
Rust Python Bindings
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
#[macro_use] extern crate cpython; | |
use cpython::{PyResult, Python}; | |
py_module_initializer!(libmyrustlib, initlibmyrustlib, PyInit_libmyrustlib, |py, m| { | |
m.add(py, "__doc__", "This module is implemented in Rust.")?; | |
m.add(py, "rust_concat", py_fn!(py, rust_concat(val: i64)))?; | |
Ok(()) | |
}); | |
fn rust_concat(_: Python, val: i64) -> PyResult<String> { | |
let mut result = String::new(); | |
for i in 0..val { | |
result.push_str(&i.to_string()); | |
} | |
Ok(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment