Open pacu opened 3 months ago
In Go, slices can't be used as map keys. Any ideas what to do in this case?
I ended up using a String but it's not ideal. Maybe the FFI code could actually create an intermediate type that it's actually comparable?
I'm not super deep into Go, but from some light reading and asking ChatGPT, it does not seem possible to make arbitrary types compatible as map keys. In Go fixed-size arrays are valid map keys, but variable sized-arrays (slices) are not.
I think for your use case a fixed size array would work just as well, but unfortunately it looks like uniffi-rs upstream does not support fixed-size arrays.
when generating bindings for Go, the generated code fails with
invalid map key type ParticipantIdentifier
Example:
this struct is equatable yet, GoLang bindings don't generate code to make
ParticipantIdentifier
comparable in GoLangnote: this is not an issue on generated Swift Bindings
This generates these two types in Go
But there is not generated code to honor the Eq proc macro and make it possible for
ParticipantIdentifier
to be used as key on a map because the byte[] type is not comparable.Edit: This might not have a simple solution. If someone is running into this problem you probably want to encode your bytes into a comparable primitive type. It's not ideal, but it works. For example, encode the data into a hex string using
hex
crate in Rust