Improving struct init shorthand

I wished this (or Foo { *foo }) was possible quite a few times. Though I agree with @kornel about allowing some, but not all expressions: It would be confusing and hard to justify.

That's not possible, because it would break type inference in a lot of cases. A context-sensitive keyword would work:

Foo {
    some_field: some_field.into(),
}

Could be written as

Foo {
    into some_field,
}

But I'm not sure if the slight improvement in conciseness justifies introducing a new keyword.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.