提交 2d3396be 编写于 作者: B Brian Anderson

tutorial: Merge some related, small sections

上级 0e14fd6e
...@@ -742,8 +742,6 @@ struct Stack { ...@@ -742,8 +742,6 @@ struct Stack {
With a value of such a type, you can do `mystack.head += 1`. If `mut` were With a value of such a type, you can do `mystack.head += 1`. If `mut` were
omitted from the type, such an assignment would result in a type error. omitted from the type, such an assignment would result in a type error.
## Struct patterns
Structs can be destructured in `match` patterns. The basic syntax is Structs can be destructured in `match` patterns. The basic syntax is
`Name {fieldname: pattern, ...}`: `Name {fieldname: pattern, ...}`:
~~~~ ~~~~
...@@ -845,8 +843,6 @@ let my_gizmo_id = GizmoId(10); ...@@ -845,8 +843,6 @@ let my_gizmo_id = GizmoId(10);
let id_int: int = *my_gizmo_id; let id_int: int = *my_gizmo_id;
~~~~ ~~~~
## Enum patterns
For enum types with multiple variants, destructuring is the only way to For enum types with multiple variants, destructuring is the only way to
get at their contents. All variant constructors can be used as get at their contents. All variant constructors can be used as
patterns, as in this definition of `area`: patterns, as in this definition of `area`:
...@@ -862,7 +858,10 @@ fn area(sh: Shape) -> float { ...@@ -862,7 +858,10 @@ fn area(sh: Shape) -> float {
} }
~~~~ ~~~~
Another example, matching nullary enum variants: Like other patterns, a lone underscore ignores individual fields.
Ignoring all fields of a variant can be written `Circle(*)`. As in
their introductory form, nullary enum patterns are written without
parentheses.
~~~~ ~~~~
# type Point = {x: float, y: float}; # type Point = {x: float, y: float};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册