Skip to content

Commit ec69dea

Browse files
committed
doc: Fix tutorial for struct deref
1 parent 2d8fbba commit ec69dea

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

doc/tutorial.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,6 @@ synonym for an existing type but is rather its own distinct type.
793793
struct GizmoId(int);
794794
~~~~
795795

796-
For convenience, you can extract the contents of such a struct with the
797-
dereference (`*`) unary operator:
798-
799-
~~~~
800-
# struct GizmoId(int);
801-
let my_gizmo_id: GizmoId = GizmoId(10);
802-
let id_int: int = *my_gizmo_id;
803-
~~~~
804-
805796
Types like this can be useful to differentiate between data that have
806797
the same underlying type but must be used in different ways.
807798

@@ -811,7 +802,16 @@ struct Centimeters(int);
811802
~~~~
812803

813804
The above definitions allow for a simple way for programs to avoid
814-
confusing numbers that correspond to different units.
805+
confusing numbers that correspond to different units. Their integer
806+
values can be extracted with pattern matching:
807+
808+
~~~
809+
# struct Inches(int);
810+
811+
let length_with_unit = Inches(10);
812+
let Inches(integer_length) = length_with_unit;
813+
println!("length is {} inches", integer_length);
814+
~~~
815815

816816
# Functions
817817

0 commit comments

Comments
 (0)