1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-07-12 17:20:14 +02:00

Cross-reference the 'Fundamentals' module with the 'Idiomatic Rust' module

This commit is contained in:
LukeMathWalker
2025-07-02 17:27:34 +02:00
parent edfe9e8348
commit 51d050ebc1
2 changed files with 6 additions and 0 deletions

View File

@ -34,6 +34,10 @@ assert_ne!(UserId(1), UserId(2));
<details> <details>
- Students should have encountered the newtype pattern in the "Fundamentals"
course, when they learned about
[tuple structs](../../user-defined-types/tuple-structs.md).
- Run the example to show students the error message from the compiler. - Run the example to show students the error message from the compiler.
- Modify the example to use a typealias instead of a newtype, such as - Modify the example to use a typealias instead of a newtype, such as

View File

@ -43,6 +43,8 @@ fn main() {
- The value passed some validation when it was created, so you no longer have - The value passed some validation when it was created, so you no longer have
to validate it again at every use: `PhoneNumber(String)` or to validate it again at every use: `PhoneNumber(String)` or
`OddNumber(u32)`. `OddNumber(u32)`.
- The newtype pattern is covered extensively in the
["Idiomatic Rust" module](../idiomatic/leveraging-the-type-system/newtype-pattern.md).
- Demonstrate how to add a `f64` value to a `Newtons` type by accessing the - Demonstrate how to add a `f64` value to a `Newtons` type by accessing the
single field in the newtype. single field in the newtype.
- Rust generally doesn’t like inexplicit things, like automatic unwrapping or - Rust generally doesn’t like inexplicit things, like automatic unwrapping or