An open API service indexing awesome lists of open source software.

https://github.com/xyproto/rust-go-example

An example of how to combine Rust and Go in the same program
https://github.com/xyproto/rust-go-example

example go rust

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# rust-go-example

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

This function:

```go
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):

```rust
result = Add(x, y);
```

And the answer is printed out:

```rust
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.