Skip to content

Doc field init shorthand#405

Closed
ghost wants to merge 1 commit into
masterfrom
unknown repository
Closed

Doc field init shorthand#405
ghost wants to merge 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jan 16, 2017

Copy link
Copy Markdown

Added "field init shorthand" follow by RFC 1682

@ghost ghost mentioned this pull request Jan 16, 2017
5 tasks

@steveklabnik steveklabnik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Some nits. This is going to have to sit until the feature is actually stabilized, but I'm happy to have it until then!

Comment thread src/ch05-00-structs.md
To get a particular value out of a struct, we can use dot notation. If we
wanted just this user’s email address, we can say `user1.email`.

We can initializing a data structure (struct, enum, union) with named fields, by writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a compact syntax for initialization, with less duplication:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you wrap this to 80 columns please?

Comment thread src/ch05-00-structs.md
We can initializing a data structure (struct, enum, union) with named fields, by writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a compact syntax for initialization, with less duplication:

```
#![feature(field_init_shorthand)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove this, please? we aren't going to put it in the book until it's stable.

Comment thread src/ch05-00-structs.md

#[derive(Debug)]
struct Person<'a> {
name: &'a str,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this a String?

Comment thread src/ch05-00-structs.md

fn main() {
// Create struct with field init shorthand
let name = "Peter";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and then use String::from here?

@carols10cents carols10cents added the blocked upstream Blocked on a change that needs to happen in a different repo first label Jan 18, 2017
@carols10cents carols10cents added this to the ch5 milestone Jan 18, 2017
@steveklabnik

Copy link
Copy Markdown
Contributor

This is now stable in nightly! @HnGiang any interest in fixing up the review issues here?

steveklabnik added a commit that referenced this pull request Mar 23, 2017
From RFC 1682.

This is an updated version of #405.

cc rust-lang/rust#39096
@steveklabnik

Copy link
Copy Markdown
Contributor

I've updated this and committed it as e90abc5, thank you! ❤️

gypsydave5 pushed a commit to gypsydave5/book that referenced this pull request Nov 17, 2017
From RFC 1682.

This is an updated version of rust-lang#405.

cc rust-lang/rust#39096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked upstream Blocked on a change that needs to happen in a different repo first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants