mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 01:42:55 +00:00
Create more involved example
This commit is contained in:
Binary file not shown.
@@ -3,4 +3,4 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void rust_function(void);
|
||||
void rust_function(uint32_t a);
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::TestFunc;
|
||||
use crate::{TestFunc, TMP_TEST};
|
||||
|
||||
#[test]
|
||||
fn run_test() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user