File tree Expand file tree Collapse file tree
leveraging-the-type-system
polymorphism/from-oop-to-rust Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -481,7 +481,7 @@ SPDX-License-Identifier: CC-BY-4.0
481481- [ Leveraging the Type System] ( idiomatic/leveraging-the-type-system.md )
482482 - [ Newtype Pattern] ( idiomatic/leveraging-the-type-system/newtype-pattern.md )
483483 - [ Semantic Confusion] ( idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md )
484- - [ Parse, Don't Validate ] ( idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md )
484+ - [ Enforce Invariants ] ( idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md )
485485 - [ Is It Encapsulated?] ( idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md )
486486 - [ RAII] ( idiomatic/leveraging-the-type-system/raii.md )
487487 - [ Drop Skipped] ( idiomatic/leveraging-the-type-system/raii/drop_skipped.md )
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ SPDX-License-Identifier: CC-BY-4.0
99
1010# Extension Traits
1111
12- It may desirable to ** extend** foreign types with new inherent methods. For
13- example, allow your code to check if a string is a palindrome using
14- method-calling syntax: ` s.is_palindrome() ` .
12+ It may desirable to ** extend** foreign types with new methods. For example,
13+ allow your code to check if a string is a palindrome using method-calling
14+ syntax: ` s.is_palindrome() ` .
1515
1616It might feel natural to reach out for an ` impl ` block:
1717
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Copyright 2025 Google LLC
77SPDX-License-Identifier: CC-BY-4.0
88-->
99
10- # Parse, Don't Validate
10+ # Enforce Invariants at Construction
1111
1212The newtype pattern can be leveraged to enforce _ invariants_ .
1313
@@ -25,7 +25,6 @@ impl Username {
2525 if username.len() > 32 {
2626 return Err(InvalidUsername::TooLong { len: username.len() })
2727 }
28- // Other validation checks...
2928 Ok(Self(username))
3029 }
3130
Original file line number Diff line number Diff line change @@ -60,8 +60,8 @@ fn main() {
6060 fails, the file will still be cleaned up. This ordering is essential for
6161 correctness.
6262
63- - The ` guard() ` creates a ` ScopeGuard ` instance. It a user-defined value (in
64- this case, ` path ` ) and the cleanup closure that later receives this value.
63+ - The ` guard() ` creates a ` ScopeGuard ` instance. It takes a user-defined value
64+ (in this case, ` path ` ) and the cleanup closure that later receives this value.
6565
6666- The guard's closure runs on scope exit unless it is _ defused_ with
6767 ` ScopeGuard::into_inner ` (removing the value so the guard does nothing on
@@ -75,8 +75,7 @@ fn main() {
7575
7676- This pattern is also useful when you don't control the cleanup strategy of the
7777 resource object. In this example, ` File::drop() ` closes the file but does not
78- delete it, and we can't change the standard library to delete the file instead
79- (nor should we, it is not a good idea anyway).
78+ delete it.
8079
8180- The ` scopeguard ` crate also supports cleanup strategies via the
8281 [ ` Strategy ` ] ( https://docs.rs/scopeguard/latest/scopeguard/trait.Strategy.html )
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ fn main() {
7272 lifetimes have a common shorter lifetime (AKA being subtyped).
7373
7474- Note: This slide compiles, by the end of this slide it should only compile
75- when ` subtyped_lifetimes ` is commented out.
75+ when ` try_coerce_lifetimes ` is commented out.
7676
7777- There are two important parts of this code:
7878 - The ` impl for<'a> ` bound on the closure passed to ` lifetime_separator ` .
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Copyright 2025 Google LLC
77SPDX-License-Identifier: CC-BY-4.0
88-->
99
10- ## Typestate Pattern: Problem
10+ # Typestate Pattern: Problem
1111
1212How can we ensure that only valid operations are allowed on a value based on its
1313current state?
Original file line number Diff line number Diff line change @@ -57,8 +57,8 @@ impl SomeTrait for Data {
5757 interchangeably, without being able to specify a concrete type or if a type is
5858 identical to another.
5959
60- For operations like equality, comparison this allows for comparison and
61- equality that throws and error or otherwise panics.
60+ For operations like equality or comparison this allows for comparison and
61+ equality that throws an error or otherwise panics.
6262
6363- Multiple sources of truth for what makes up a data structure and how it
6464 behaves:
You can’t perform that action at this time.
0 commit comments