How to pass golang array to rust

like the title,is here anyone can help me~ :pray:

It's not clear what you are trying to do. Are you looking for calling Rust from Go through FFI?

yes, i am testing FFI. And i tried many methods to pass an array from go to rust, all failed.

It is not, in general, possible to pass arbitrary data between languages, because each language has its own, different representation of data structures. The only interoperable way is, practically speaking, pretending to go through C. For this reason, you can only transfer types with a simple enough layout and contents (e.g. "plain old data" with no behavior, no heap pointers, no destructors, etc.).

If you have an array of such data, then you will have to obtain its length and a pointer to the first element and pass those over as separate parameters.

1 Like

thank you! did you mean like this?But it only get the first value

That's my fault. I'm not using the right data type, it working now! Thanks for your help!

In the future, please post code, compiler diagnostics, and command-line output as text (inside code blocks), not screenshots. It's easier for everyone to read, copy/paste, etc.

```
pub unsafe extern "C" fn double_input() {
}
```

```go
func TestR() {
}
```

```text
3
0
0
```
3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.