Porting from C to Rust

I'm trying to port this to Rust (last example on the page, that is fully working example in C):

I'm stuck on that line:

 gpointer data[]={button, socket, entry, expander};

Can anyone help with this, that is, how it should be ported from C to Rust?
Thank you

It looks like an array of length four, so you could use the type [gpointer; 4].

1 Like

This syntax means that data is a stack-allocated fixed-size array, the initial contents of which are given in the braces. A direct translation to Rust would thus look like this:

let data: [gpointer; 4] = [button, socket, entry, expander];

Note that the "array" part comes from the [] after data. For more general types, e.g. foo bar = { ... }, this would involve aggregate initialization (note that the link is for C++, but AFAIK this specific part works mostly the same in C; in C++ brace initialization can have more complex meaning).

1 Like

Thanks for the answer. Indeed it helped.

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.