Although anonymous structures are not supported, you can localize them to do almost as described in version C:
fn main() {
struct Example<'a> {
name: &'a str
};
let obj = Example { name: "Simon" };
let obj2 = Example { name: "ideasman42" };
println!("{}", obj.name); // Simon
println!("{}", obj2.name); // ideasman42
}
Playground
Another option is a tuple:
fn main() {
let obj = (1, 0, 1);
println!("{}", obj.0);
println!("{}", obj.1);
println!("{}", obj.2);
}
Playground
source
share