You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-12 09:10:40 +02:00
Cross-reference the 'Fundamentals' module with the 'Idiomatic Rust' module
This commit is contained in:
@ -34,6 +34,10 @@ assert_ne!(UserId(1), UserId(2));
|
||||
|
||||
<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.
|
||||
|
||||
- Modify the example to use a typealias instead of a newtype, such as
|
||||
|
@ -43,6 +43,8 @@ fn main() {
|
||||
- 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)`.
|
||||
- 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
|
||||
single field in the newtype.
|
||||
- Rust generally doesn’t like inexplicit things, like automatic unwrapping or
|
||||
|
Reference in New Issue
Block a user