File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -793,15 +793,6 @@ synonym for an existing type but is rather its own distinct type.
793793struct 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-
805796Types like this can be useful to differentiate between data that have
806797the same underlying type but must be used in different ways.
807798
@@ -811,7 +802,16 @@ struct Centimeters(int);
811802~~~~
812803
813804The 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
You can’t perform that action at this time.
0 commit comments