@@ -734,6 +734,7 @@ omitted from the type, such an assignment would result in a type error.
734
734
735
735
Structs can be destructured in ` match ` patterns. The basic syntax is
736
736
` Name {fieldname: pattern, ...} ` :
737
+
737
738
~~~~
738
739
# struct Point { x: float, y: float }
739
740
# let mypoint = Point { x: 0.0, y: 0.0 };
@@ -747,6 +748,35 @@ In general, the field names of a struct do not have to appear in the same
747
748
order they appear in the type. When you are not interested in all
748
749
the fields of a struct, a struct pattern may end with ` , _ ` (as in
749
750
` Name {field1, _} ` ) to indicate that you're ignoring all other fields.
751
+ Additionally, struct fields have a shorthand matching form that simply
752
+ reuses the field name as the binding name.
753
+
754
+ ~~~
755
+ # struct Point { x: float, y: float }
756
+ # let mypoint = Point { x: 0.0, y: 0.0 };
757
+ match mypoint {
758
+ Point { x, _ } => { io::println(x.to_str()) }
759
+ }
760
+ ~~~
761
+
762
+ Structs are the only type in Rust that may have user-defined destructors,
763
+ using ` drop ` blocks, inside of which the struct's value may be referred
764
+ to with the name ` self ` .
765
+
766
+ ~~~
767
+ struct TimeBomb {
768
+ explosivity: uint,
769
+
770
+ drop {
771
+ for iter::repeat(explosivity) {
772
+ io::println(fmt!("blam!"));
773
+ }
774
+ }
775
+ }
776
+ ~~~
777
+
778
+ > *** Note*** : This destructor syntax is temporary. Eventually destructors
779
+ > will be defined for any type using [ traits] ( #traits ) .
750
780
751
781
## Enums
752
782
0 commit comments