Create more involved example

This commit is contained in:
Arthur Petukhovsky
2023-05-30 16:43:33 +00:00
parent a77fc2c5ff
commit ac82b34c64
5 changed files with 15 additions and 4 deletions

Binary file not shown.

View File

@@ -3,4 +3,4 @@
#include <stdint.h>
#include <stdlib.h>
void rust_function(void);
void rust_function(uint32_t a);

View File

@@ -8,9 +8,20 @@ pub mod bindings {
pub use bindings::TestFunc;
use std::cell::RefCell;
thread_local! {
pub static TMP_TEST: RefCell<Vec<u32>> = RefCell::new(vec![]);
}
#[no_mangle]
pub extern "C" fn rust_function() {
pub extern "C" fn rust_function(a: u32) {
println!("Hello from Rust!");
println!("a: {}", a);
TMP_TEST.with(|f| {
f.borrow_mut().push(a);
println!("TMP_TEST: {:?}", f.borrow());
});
}
#[cfg(test)]

View File

@@ -1,4 +1,4 @@
use crate::TestFunc;
use crate::{TestFunc, TMP_TEST};
#[test]
fn run_test() {

View File

@@ -4,6 +4,6 @@
int TestFunc(int a, int b) {
printf("TestFunc: %d + %d = %d\n", a, b, a + b);
rust_function();
rust_function(0);
return a + b;
}