Skip to content

Commit 1bbfd48

Browse files
committed
---
yaml --- r: 31035 b: refs/heads/incoming c: 09df3ed h: refs/heads/master i: 31033: 350f3d4 31031: 9f23016 v: v3
1 parent a230541 commit 1bbfd48

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 8fc60af441a1375ee73a0efe4524b54ff039e69a
9+
refs/heads/incoming: 09df3ed8f1abdbeaf6b6ae9c08c9446341965918
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ omitted from the type, such an assignment would result in a type error.
734734

735735
Structs can be destructured in `match` patterns. The basic syntax is
736736
`Name {fieldname: pattern, ...}`:
737+
737738
~~~~
738739
# struct Point { x: float, y: float }
739740
# 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
747748
order they appear in the type. When you are not interested in all
748749
the fields of a struct, a struct pattern may end with `, _` (as in
749750
`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).
750780
751781
## Enums
752782

0 commit comments

Comments
 (0)