mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 11:39:42 +02:00
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 <qwandor@google.com>
This commit is contained in:
parent
d1588e4f2f
commit
c109dabf5f
@ -31,3 +31,11 @@ fn main() {
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
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)`.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user