Skip to content

Commit 66b4705

Browse files
Apply suggestions from code review
Co-authored-by: Dmitri Gribenko <[email protected]>
1 parent 9cc30ac commit 66b4705

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ impl Username {
3535

3636
- The newtype pattern, combined with Rust's module and visibility system, can be
3737
used to _guarantee_ that instances of a given type satisfy a set of
38-
invariants.\
38+
invariants.
39+
3940
In the example above, the raw `String` stored inside the `Username` struct
4041
can't be accessed directly from other modules or crates, since it's not marked
4142
as `pub` or `pub(in ...)`. Consumers of the `Username` type are forced to use
4243
the `new` method to create instances. In turn, `new` performs validation, thus
4344
ensuring that all instances of `Username` satisfy those checks.
4445

4546
- The `as_str` method allows consumers to access the raw string representation
46-
(e.g. to store it in a database) but, thanks to Rust's borrow checker, they
47+
(e.g., to store it in a database) but, thanks to Rust's borrow checker, they
4748
can't modify it.
4849

4950
- Stress the importance of evaluating _the entire API surface_ exposed by a

src/idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ minutes: 5
44

55
# Semantic Confusion
66

7-
There is room for confusion whenever a function takes multiple arguments of the
8-
same type:
7+
When a function takes multiple arguments of the same type, call sites are unclear:
98

109
```rust
1110
# struct LoginError;
@@ -21,7 +20,7 @@ pub fn login(username: &str, password: &str) -> Result<(), LoginError> {
2120
login(password, username);
2221
```
2322

24-
The newtype pattern can be used to prevent this class of errors at compile time:
23+
The newtype pattern can prevent this class of errors at compile time:
2524

2625
```rust
2726
pub struct Username(String);
@@ -50,7 +49,7 @@ login(password, username);
5049

5150
- Nonetheless, note that there are legitimate scenarios where a function may
5251
take multiple arguments of the same type. In those scenarios, if correctness
53-
is of paramount important, consider using a struct with named fields as input:
52+
is of paramount importance, consider using a struct with named fields as input:
5453
```rust
5554
pub struct LoginArguments {
5655
pub username: &str,

0 commit comments

Comments
 (0)