Closed
Conversation
5 tasks
steveklabnik
suggested changes
Jan 17, 2017
Contributor
steveklabnik
left a comment
There was a problem hiding this comment.
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!
| 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: |
Contributor
There was a problem hiding this comment.
could you wrap this to 80 columns please?
| 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)] |
Contributor
There was a problem hiding this comment.
could you remove this, please? we aren't going to put it in the book until it's stable.
|
|
||
| #[derive(Debug)] | ||
| struct Person<'a> { | ||
| name: &'a str, |
Contributor
There was a problem hiding this comment.
Could you make this a String?
|
|
||
| fn main() { | ||
| // Create struct with field init shorthand | ||
| let name = "Peter"; |
Contributor
There was a problem hiding this comment.
... and then use String::from here?
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added "field init shorthand" follow by RFC 1682