File tree 1 file changed +10
-10
lines changed
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.
793
793
struct GizmoId(int);
794
794
~~~~
795
795
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
-
805
796
Types like this can be useful to differentiate between data that have
806
797
the same underlying type but must be used in different ways.
807
798
@@ -811,7 +802,16 @@ struct Centimeters(int);
811
802
~~~~
812
803
813
804
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
+ ~~~
815
815
816
816
# Functions
817
817
You can’t perform that action at this time.
0 commit comments