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
- Host: GitHub
- URL: https://github.com/xyproto/rust-go-example
- Owner: xyproto
- License: bsd-3-clause
- Created: 2023-08-02T11:02:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-02T14:08:43.000Z (about 2 years ago)
- Last Synced: 2025-03-29T03:03:54.789Z (6 months ago)
- Topics: example, go, rust
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.