diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-01-04 12:13:31 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-01-04 14:44:14 -0800 |
| commit | ec69dea6f7eed9854504dd83aa136900d48fafef (patch) | |
| tree | 5dca296fa359cad15f6ca1ff1c338d5ea445bfc3 /doc/tutorial.md | |
| parent | 2d8fbba57df502a47b2818405c6ab349b929142f (diff) | |
| download | rust-ec69dea6f7eed9854504dd83aa136900d48fafef.tar.gz rust-ec69dea6f7eed9854504dd83aa136900d48fafef.zip | |
doc: Fix tutorial for struct deref
Diffstat (limited to 'doc/tutorial.md')
| -rw-r--r-- | doc/tutorial.md | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md index 4edbf171065..ffef6d7f91f 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -793,15 +793,6 @@ synonym for an existing type but is rather its own distinct type. struct GizmoId(int); ~~~~ -For convenience, you can extract the contents of such a struct with the -dereference (`*`) unary operator: - -~~~~ -# struct GizmoId(int); -let my_gizmo_id: GizmoId = GizmoId(10); -let id_int: int = *my_gizmo_id; -~~~~ - Types like this can be useful to differentiate between data that have the same underlying type but must be used in different ways. @@ -811,7 +802,16 @@ struct Centimeters(int); ~~~~ The above definitions allow for a simple way for programs to avoid -confusing numbers that correspond to different units. +confusing numbers that correspond to different units. Their integer +values can be extracted with pattern matching: + +~~~ +# struct Inches(int); + +let length_with_unit = Inches(10); +let Inches(integer_length) = length_with_unit; +println!("length is {} inches", integer_length); +~~~ # Functions |
