[rust-dev] Work with records in C style

Alexander Stavonin a.stavonin at gmail.com
Fri Apr 13 05:39:10 PDT 2012


When we want to create a new record we have to enumerate all fields during creation:

let base = {x: 1, y: 2, z: 3};

This idea is very good, until we are working with small records, without internal subrecords or with low count of field. What is the best way for big records initializing? For example:

type sockaddr4_in = {sin_family: i16, sin_port: u16, sin_addr: in4_addr,
                     sin_zero: (x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x)};

How to initialize it quick and easy? Idea with using "with" keyword is not too god, as in that case I have to enumerate all fields at list once.
How about C/C++ style, something like that?

let addr = sockaddr4_in::any_keyword_as_you_like();
or
let addr = sockaddr4_in();


More information about the Rust-dev mailing list