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 union declarations #30

Closed
nrc opened this issue Oct 17, 2016 · 12 comments
Closed

struct and union declarations #30

nrc opened this issue Oct 17, 2016 · 12 comments

Comments

@nrc
Copy link
Member

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 mentioned this issue Oct 17, 2016
10 tasks
@nrc
Copy link
Member Author

nrc commented Oct 17, 2016

Single-line tuple structs are already covered in the guide: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md#tuples-and-tuple-structs

@nrc nrc added the P-high label Oct 17, 2016
@strega-nil
Copy link

strega-nil commented Oct 17, 2016

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
Copy link
Member Author

nrc commented Oct 17, 2016

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

@joshtriplett
Copy link
Member

joshtriplett commented Oct 17, 2016

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

@bluss
Copy link
Member

bluss commented Nov 3, 2016

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
Copy link

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
Copy link
Member

bluss commented Nov 5, 2016

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
Copy link
Member Author

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 mentioned this issue Nov 6, 2016
@nrc
Copy link
Member Author

nrc commented Nov 29, 2016

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

@johnthagen
Copy link
Contributor

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

@nrc nrc self-assigned this Jan 20, 2017
@nrc
Copy link
Member Author

nrc commented Jan 20, 2017

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

@nrc
Copy link
Member Author

nrc commented May 1, 2017

Closed by #53

@nrc nrc closed this as completed May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants