1
0
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:
Igor Petruk 2023-01-23 11:38:37 +00:00 committed by GitHub
parent d1588e4f2f
commit c109dabf5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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>