Skip to content

RFC: Add syntaxic sugar for struct expressions fields from variables of the same name #306

Closed
@rust-highfive

Description

@rust-highfive

Issue by SimonSapin
Sunday Feb 02, 2014 at 12:29 GMT

For earlier discussion, see rust-lang/rust#11990

This issue was labelled with: A-parser, B-RFC in the Rust repository


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

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions