milksnake icon indicating copy to clipboard operation
milksnake copied to clipboard

Vector containing user-defined structs

Open HagaiHargil opened this issue 7 years ago • 0 comments

Hello and thanks for milksnake!

I'm having issues using the package when I wish to run a Rust function that returns a vector of tuples. I'm basically trying to replicate Shepmaster's excellent SO answer since my use case is very similar, but simpler - I don't wish to both send and receive a vector of tuples from Python, I only wish to receive one back.

When I build his code using milksnake with the slight change I just mentioned, everything compiles successfully, and I even receive my vector back. Unfortunately, Python thinks it's an Array type, which is the name of the user-defined type in Rust, and I can't find a way to "dereference" it into a standard Python list. milksnake doesn't directly expose user-defined Rust types like Array, and I'm not sure which magic tricks I should envoke from ctypes to make it work. The object I receive is the following:

arr = lib.convert_vec()
print(arr.data)  # <cdata 'void *' 0x00000282F3D28160>
print(arr.size)  # 7 (works)

Thanks!

HagaiHargil avatar Sep 04 '18 20:09 HagaiHargil