Add Python to Rust example
This commit is contained in:
4
python-to-rust/src/lib.rs
Normal file
4
python-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
8
python-to-rust/src/main.py
Normal file
8
python-to-rust/src/main.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from ctypes import cdll
|
||||
|
||||
lib = cdll.LoadLibrary('target/libdouble_input.so')
|
||||
double_input = lib.double_input
|
||||
|
||||
input = 4
|
||||
output = double_input(input)
|
||||
print(str(input) + " * 2 = " + str(output))
|
||||
Reference in New Issue
Block a user