Skip to content

Commit b13adb6

Browse files
committed
---
yaml --- r: 22327 b: refs/heads/snap-stage3 c: 09df3ed h: refs/heads/master i: 22325: 82a93ac 22323: 0e72c90 22319: e0aee4c v: v3
1 parent 4febc42 commit b13adb6

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8fc60af441a1375ee73a0efe4524b54ff039e69a
4+
refs/heads/snap-stage3: 09df3ed8f1abdbeaf6b6ae9c08c9446341965918
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)