]> git.lizzy.rs Git - rust.git/commitdiff
Simplify wording & fix test src/doc
authorSon <leson.phung@gmail.com>
Fri, 3 Feb 2017 12:51:50 +0000 (23:51 +1100)
committerSon <leson.phung@gmail.com>
Fri, 3 Feb 2017 12:51:50 +0000 (23:51 +1100)
src/doc/book/structs.md
src/doc/reference.md

index 811f7b4196768f3185e841168d9dca528675287d..dcf74cbb0a7c47660fede441837ccbf717b3c7fe 100644 (file)
@@ -117,9 +117,9 @@ fn main() {
 }
 ```
 
-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:
+Initialization of a data structure (struct, enum, union) can be simplified if
+fields of the data structure are initialized with variables which has same
+names as the fields.
 
 ```
 #![feature(field_init_shorthand)]
index 6f2ce5fd8d1c50db48ba1daa061dddfa5a68f599..8139a712bddb25e7c9cdd71adf8621f03df32e41 100644 (file)
@@ -2770,8 +2770,13 @@ shorthand for `field: field`.
 Example:
 
 ```
-let a = SomeStruct { field1, field2: expression, field3 };
-let b = SomeStruct { field1: field1, field2: expression, field3: field3 };
+# #![feature(field_init_shorthand)]
+# struct Point3d { x: i32, y: i32, z: i32 }
+# let x = 0;
+# let y_value = 0;
+# let z = 0;
+Point3d { x: x, y: y_value, z: z };
+Point3d { x, y: y_value, z };
 ```
 
 ### Block expressions