Add rust to go dynamic library example.
This commit is contained in:
10
rust-to-go-dynamic/src/double.go
Normal file
10
rust-to-go-dynamic/src/double.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
//export DoubleInput
|
||||
func DoubleInput(input int32) int32 {
|
||||
return input * 2
|
||||
}
|
||||
|
||||
func main() {}
|
||||
12
rust-to-go-dynamic/src/main.rs
Normal file
12
rust-to-go-dynamic/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "double_input")]
|
||||
extern {
|
||||
fn DoubleInput(input: libc::c_int) -> libc::c_int;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = 2;
|
||||
let output = unsafe { DoubleInput(input) };
|
||||
println!("{} * 2 = {}", input, output);
|
||||
}
|
||||
Reference in New Issue
Block a user