From c109dabf5f0ebad73e5fadf3f98346651e29edbe Mon Sep 17 00:00:00 2001 From: Igor Petruk Date: Mon, 23 Jan 2023 11:38:37 +0000 Subject: [PATCH] Update tuple-structs.md (#226) * Update tuple-structs.md I am adding more information about newtypes. The speaker can get questions about it or may wish to encourage this great pattern. * Fix typos and explanation Co-authored-by: Andrew Walbran --- src/structs/tuple-structs.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/structs/tuple-structs.md b/src/structs/tuple-structs.md index 0e8ea6af..4ac7e07c 100644 --- a/src/structs/tuple-structs.md +++ b/src/structs/tuple-structs.md @@ -31,3 +31,11 @@ fn main() { } ``` + +
+ +Newtypes are a great way to encode additional information about the value in a primitive type, for example: + * The number is measured in some units: `Newtons` in the example above. + * The value passed some validation when it was created, so you no longer have to validate it again at every use: 'PhoneNumber(String)` or `OddNumber(u32)`. + +