File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
src/idiomatic/leveraging-the-type-system/newtype-pattern Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -48,13 +48,15 @@ impl Username {
48
48
can't modify it.
49
49
50
50
- Stress the importance of evaluating _ the entire API surface_ exposed by a
51
- newtype to determine if invariants are indeed bullet-proof.\
51
+ newtype to determine if invariants are indeed bullet-proof.
52
+
52
53
It is crucial to consider all possible interactions, including trait
53
54
implementations, that may allow users to bypass the invariants. For example,
54
55
if the ` Username ` type implements the ` DerefMut ` trait, users can modify the
55
56
underlying string directly, bypassing the validation checks in ` new ` .
56
57
57
- - Type-level invariants have second-order benefits.\
58
+ - Type-level invariants have second-order benefits.
59
+
58
60
The input is validated once, at the boundary, and the rest of the program can
59
61
rely on the invariants being upheld. We can avoid redundant validation and
60
62
"defensive programming" checks throughout the program, reducing noise and
You can’t perform that action at this time.
0 commit comments