You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when it comes to the example above, there will come a weird bug that Go side will exchange, well I wonder if I explain clearly, values of these two fields.
After thinking for a while, I come to the solution. It's simple: don't forget #[repr(C)], which assures that the order, size, and alignment of fields is exactly what you would expect from C that acting as FFI bridge between Rust and Go.
BTW, I also want to share my experience here: if you pass a string from Rust to Go, you'd better make a deep copy especially when it acts like config, etc, otherwise if original one is dropped within Rust side, you may encounter with unfarished behaviors.
The text was updated successfully, but these errors were encountered:
According to offcial example, we should add
rust2go::R2G
attribute to structs that will be passed to Go side.However, when it comes to the example above, there will come a weird bug that Go side will exchange, well I wonder if I explain clearly, values of these two fields.
After thinking for a while, I come to the solution. It's simple: don't forget
#[repr(C)]
, which assures that the order, size, and alignment of fields is exactly what you would expect from C that acting as FFI bridge between Rust and Go.BTW, I also want to share my experience here: if you pass a string from Rust to Go, you'd better make a deep copy especially when it acts like config, etc, otherwise if original one is dropped within Rust side, you may encounter with unfarished behaviors.
The text was updated successfully, but these errors were encountered: