struct and union declarations #30

Open
nrc opened this Issue Oct 17, 2016 · 11 comments

Projects

None yet

6 participants

@nrc
Collaborator
nrc commented Oct 17, 2016

I'd like to discuss generics separately (#29). I'd like to include unit and tuple structs here.

@nrc nrc added the E-easy label Oct 17, 2016
@nrc nrc referenced this issue Oct 17, 2016
Open

Items #25

2 of 7 tasks complete
@nrc
Collaborator
nrc commented Oct 17, 2016
@nrc nrc added the P-high label Oct 17, 2016
@ubsan
Contributor
ubsan commented Oct 17, 2016 edited

I prefer:

struct Foo /* <- must be on one line */ { /* <- on the first line if it fits, otherwise pull it down */
  b: B, /* <- indented once, must end with a trailing comma */
  long_name:
    LongName, /* <- if required, pull the type name down to the next line and indent again */
} /* <- on it's own line */
@nrc
Collaborator
nrc commented Oct 17, 2016

And to clarify - a trailing comma on the last field?

@joshtriplett
Member
joshtriplett commented Oct 17, 2016 edited

@nrc Yes. That avoids having to add a comma when adding another field, or delete a comma when deleting a field.

@bluss
bluss commented Nov 3, 2016 edited

Edit: Where clauses are a separate issue, see #38


What about structs with trait bounds?

struct Peekable<I>
    where I: Iterator,
          I::Item: Debug, // This is only to illustrate more bounds
{
    peek: Option<I::Item>,
    iter: I,
}
  • If the where clause is treated as a list, it too should always have a trailing comma; new additions go on a new line.
@Screwtapello

I'm not a fan of visual identing, and it seems like the tone in other issues is against it. I'd rather have:

struct Peekable<I> where // 'where' on the same line, following the example of '{'
    I: Iterator,         // one block indent, just like struct fields or any other list item
    I::Item: Debug,      // trailing comma, of course
{ // visually ends the 'where' items and begins the struct items
    peek: Option<I::Item>,
    iter: I,
}
@bluss
bluss commented Nov 5, 2016 edited

A hanging where works well for functions and methods too (they often have longer initial lines), so taken together I prefer it for all of them for consistency. A where at the end of a line can be far removed from the actual where clauses, so I don't like reading it that way. It's also been the prevailing style inside the rust project itself, what I can see.

@nrc
Collaborator
nrc commented Nov 6, 2016

I'd like to also discuss where clauses separately, since they equally affect functions, traits etc., I created #38 for that.

@nrc nrc referenced this issue Nov 6, 2016
Open

Where clauses #38

@nrc
Collaborator
nrc commented Nov 29, 2016

I think this is ready for FCP, summarised in #30 (comment).

@johnthagen

@nrc I would like to take a crack at this one.

@nrc nrc self-assigned this Jan 20, 2017
@nrc
Collaborator
nrc commented Jan 20, 2017

assigning to myself for mentoring and so we can see @johnthagen is working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment