rust-go-example

An example of how to combine Rust and Go in the same program

BSD-3-CLAUSE License

Stars
4
Committers
1

rust-go-example

An example of how to combine Rust and Go in the same program.

This function:

func Add(x, y int) int {
    return x + y
}

Is compiled into a dynamic library (using cargo, build.rs and the go compiler).

The Add function is then called from Rust (using unsafe Rust and the libc crate):

result = Add(x, y);

And the answer is printed out:

println!("The answer is: {}", result);

Tested on Arch Linux.

cargo build to build and cargo run to run is enough, setting LD_LIBRARY_PATH manually was not needed here.