diff --git a/src/SUMMARY.md b/src/SUMMARY.md index f1beb92bb0c6..792fffa2d956 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -487,7 +487,7 @@ SPDX-License-Identifier: CC-BY-4.0 - [Leveraging the Type System](idiomatic/leveraging-the-type-system.md) - [Newtype Pattern](idiomatic/leveraging-the-type-system/newtype-pattern.md) - [Semantic Confusion](idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md) - - [Parse, Don't Validate](idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md) + - [Enforce Invariants](idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md) - [Is It Encapsulated?](idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md) - [RAII](idiomatic/leveraging-the-type-system/raii.md) - [Drop Skipped](idiomatic/leveraging-the-type-system/raii/drop_skipped.md) diff --git a/src/idiomatic/leveraging-the-type-system/extension-traits.md b/src/idiomatic/leveraging-the-type-system/extension-traits.md index 275493734cc8..c25fddb95ae0 100644 --- a/src/idiomatic/leveraging-the-type-system/extension-traits.md +++ b/src/idiomatic/leveraging-the-type-system/extension-traits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Extension Traits -It may desirable to **extend** foreign types with new inherent methods. For +It may desirable to **extend** foreign types with new methods. For example, allow your code to check if a string is a palindrome using method-calling syntax: `s.is_palindrome()`. diff --git a/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md b/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md index ed06bb4e2d61..8b3eff59e052 100644 --- a/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md +++ b/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md @@ -7,7 +7,7 @@ Copyright 2025 Google LLC SPDX-License-Identifier: CC-BY-4.0 --> -# Parse, Don't Validate +# Enforce Invariants at Construction The newtype pattern can be leveraged to enforce _invariants_. @@ -25,7 +25,6 @@ impl Username { if username.len() > 32 { return Err(InvalidUsername::TooLong { len: username.len() }) } - // Other validation checks... Ok(Self(username)) } diff --git a/src/idiomatic/leveraging-the-type-system/raii/scope_guard.md b/src/idiomatic/leveraging-the-type-system/raii/scope_guard.md index c020908decb4..b9d77e3f2c4e 100644 --- a/src/idiomatic/leveraging-the-type-system/raii/scope_guard.md +++ b/src/idiomatic/leveraging-the-type-system/raii/scope_guard.md @@ -60,8 +60,8 @@ fn main() { fails, the file will still be cleaned up. This ordering is essential for correctness. -- The `guard()` creates a `ScopeGuard` instance. It a user-defined value (in - this case, `path`) and the cleanup closure that later receives this value. +- The `guard()` creates a `ScopeGuard` instance. It takes a user-defined value + (in this case, `path`) and the cleanup closure that later receives this value. - The guard's closure runs on scope exit unless it is _defused_ with `ScopeGuard::into_inner` (removing the value so the guard does nothing on @@ -75,8 +75,7 @@ fn main() { - This pattern is also useful when you don't control the cleanup strategy of the resource object. In this example, `File::drop()` closes the file but does not - delete it, and we can't change the standard library to delete the file instead - (nor should we, it is not a good idea anyway). + delete it. - The `scopeguard` crate also supports cleanup strategies via the [`Strategy`](https://docs.rs/scopeguard/latest/scopeguard/trait.Strategy.html) diff --git a/src/idiomatic/leveraging-the-type-system/token-types/branded-02-phantomdata.md b/src/idiomatic/leveraging-the-type-system/token-types/branded-02-phantomdata.md index eaf73ebbd9a2..f0e692848839 100644 --- a/src/idiomatic/leveraging-the-type-system/token-types/branded-02-phantomdata.md +++ b/src/idiomatic/leveraging-the-type-system/token-types/branded-02-phantomdata.md @@ -72,7 +72,7 @@ fn main() { lifetimes have a common shorter lifetime (AKA being subtyped). - Note: This slide compiles, by the end of this slide it should only compile - when `subtyped_lifetimes` is commented out. + when `try_coerce_lifetimes` is commented out. - There are two important parts of this code: - The `impl for<'a>` bound on the closure passed to `lifetime_separator`. diff --git a/src/idiomatic/leveraging-the-type-system/typestate-pattern.md b/src/idiomatic/leveraging-the-type-system/typestate-pattern.md index 7171f016523c..c3c6d92bfcbd 100644 --- a/src/idiomatic/leveraging-the-type-system/typestate-pattern.md +++ b/src/idiomatic/leveraging-the-type-system/typestate-pattern.md @@ -7,7 +7,7 @@ Copyright 2025 Google LLC SPDX-License-Identifier: CC-BY-4.0 --> -## Typestate Pattern: Problem +# Typestate Pattern: Problem How can we ensure that only valid operations are allowed on a value based on its current state? diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md b/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md index a26d9510a707..712ca71b2540 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md @@ -57,8 +57,8 @@ impl SomeTrait for Data { interchangeably, without being able to specify a concrete type or if a type is identical to another. - For operations like equality, comparison this allows for comparison and - equality that throws and error or otherwise panics. + For operations like equality or comparison this allows for comparison and + equality that throws an error or otherwise panics. - Multiple sources of truth for what makes up a data structure and how it behaves: