Closed
Description
The general syntax for a struct pattern is:
StructName { field_name: new_variable_name }
But when the desired variable name is the same as the field name, it does not need to be repeated:
let MyStruct { name } = struct_value;
do_something_with(name);
This proposal is to add similar syntax sugar for struct expressions:
let name = …;
let struct_value = MyStruct { name };
… would be the same as:
let name = …;
let struct_value = MyStruct { name: name };
CC: @eddyb
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rapha commentedon Feb 4, 2014
OCaml has this. It's nice. I'd support it.
alexcrichton commentedon Feb 11, 2014
Closed with [my comment] on #11994.
alexcrichton commentedon Feb 11, 2014
Oh hm, no, I should leave this open.
Today's meeting notes: https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2014-02-11.md#binding-in-struct-patterns
nham commentedon Aug 18, 2014
Triage bump.
eddyb commentedon Aug 18, 2014
Shouldn't this have to go through the RFC process now?
rust-highfive commentedon Sep 24, 2014
This issue has been moved to the RFCs repo: rust-lang/rfcs#306