Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

struct and tuple literals #64

Closed
nrc opened this issue Feb 9, 2017 · 6 comments
Closed

struct and tuple literals #64

nrc opened this issue Feb 9, 2017 · 6 comments
Labels

Comments

@nrc
Copy link
Member

nrc commented Feb 9, 2017

No description provided.

@nrc nrc mentioned this issue Feb 9, 2017
14 tasks
@nrc
Copy link
Member Author

nrc commented Mar 28, 2017

structs

Single line version: Path { field1, field2 }. Note spaces before and after {, before }, no trailing comma

Mutli-line version:

Path {
    field1,
    field2,
}

Note space before {, block indent, trailing comma.

Use the mutli-line version if the literal does not fit in the line, if the fields are not short (see #47), or if any of the field sub-expressions cover multliple lines. Otherwise use the single-line version.

@nrc
Copy link
Member Author

nrc commented Mar 28, 2017

tuple variants

Unit variants are trivial.

Struct variants should follow the guidelines for structs.

Tuple variants should follow the guidelines for function calls.

@nrc
Copy link
Member Author

nrc commented Mar 28, 2017

Functional record update

Does not get a trailing comma, is otherwise treated like any other field. There is no space after the ... E.g.,

Path {
    field1,
    field2,
    ..some_expr
}

@Luthaf
Copy link

Luthaf commented May 16, 2017

Single line version: Path { field1, field2 }. Note spaces before and after {, before }, no trailing comma

I kinda dislike this, up to the point that it was my major friction point with rustfmt. I don't know how others feels about this, but I am commenting here so that this is taken in consideration =). I would be happy with this not being the default but being configurable.

To me, this have way to many spaces. I would prefer Path{field1, field2}, without the spaces. The only rationalisation I can get for this is that inline struct literals feels like constructors in C++, with the braces playing the role of parenthesis.

A version with a space before the left brace looks OK to me too: Path {field1, field2}, and it would look more like the multiline version.

@chriskrycho
Copy link

@Luthaf for a counterpoint, the most immediate predecessor for this is JavaScript's object types. It's common there to write the same kind of short structure that way there:

const field1 = 'whatever';
const field2 = 42;
const path = { field1, field2 };

I'd also note that this feels quite different from construction in C++ to me – and I want to be made more actively aware that there isn't any function call happening! – but that's just me. I think the specified default is a good default, but I certainly wouldn't be hostile to its being configurable either.

@joshtriplett
Copy link
Member

joshtriplett commented May 17, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants