Skip to content

Commit edfe9e8

Browse files
Use a terser style on slides. Avoid footnotes
1 parent ac21925 commit edfe9e8

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/idiomatic/leveraging-the-type-system.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ minutes: 5
44

55
# Leveraging the Type System
66

7-
Rust's type system is _expressive_.\
8-
We can use types and traits to build abstractions that make our code harder to
9-
misuse. In some cases, we can even go as far as enforcing correctness at
10-
_compile-time_. Quite often, these abstractions have no runtime
11-
overhead[^zero-cost].
7+
Rust's type system is _expressive_: you can use types and traits to build
8+
abstractions that make your code harder to misuse.
129

13-
The type system can also be used to model concepts and constraints from your
14-
business domain. By designing our types carefully, we can improve the clarity
15-
and maintainability of the entire codebase.
10+
In some cases, you can go as far as enforcing correctness at _compile-time_,
11+
with no runtime overhead.
12+
13+
Types and traits can model concepts and constraints from your business domain.
14+
With careful design, you can improve the clarity and maintainability of the
15+
entire codebase.
1616

1717
<details>
1818

@@ -36,12 +36,12 @@ Additional items speaker may mention:
3636
doesn't support inheritance, and object boundaries must be mindful of the
3737
constraints introduced by the borrow-checker.
3838

39+
- Mention that type-level abstractions are often referred to as "zero-cost
40+
abstractions", although the label can be misleading: the impact on compile
41+
times and code complexity may be significant.
42+
3943
</details>
4044

4145
{{%segment outline}}
4246

4347
[1]: https://pragprog.com/titles/swdddf/domain-modeling-made-functional/
44-
45-
[^zero-cost]: They often referred to as "zero-cost abstractions", although the
46-
label can be misleading: the impact on compile times and code complexity may
47-
be significant.

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,26 @@ impl Username {
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
3838
invariants.\
39-
In the example above, the raw `String` stored inside the
40-
`Username` struct can't be accessed directly from other modules or crates,
41-
since it's not marked as `pub` or `pub(in ...)`. Consumers of the `Username`
42-
type are forced to use the `new` method to create instances. In turn, `new`
43-
performs validation, thus ensuring that all instances of `Username` satisfy
44-
those checks.
39+
In the example above, the raw `String` stored inside the `Username` struct
40+
can't be accessed directly from other modules or crates, since it's not marked
41+
as `pub` or `pub(in ...)`. Consumers of the `Username` type are forced to use
42+
the `new` method to create instances. In turn, `new` performs validation, thus
43+
ensuring that all instances of `Username` satisfy those checks.
4544

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

50-
- Stress the importance of evaluating _the entire API surface_ exposed by a newtype
51-
to determine if invariants are indeed bullet-proof.\
52-
It is crucial to consider all possible interactions, including trait implementations,
53-
that may allow users to bypass the invariants. For example, if the `Username`
54-
type implements the `DerefMut` trait, users can modify the underlying string
55-
directly, bypassing the validation checks in `new`.
49+
- Stress the importance of evaluating _the entire API surface_ exposed by a
50+
newtype to determine if invariants are indeed bullet-proof.\
51+
It is crucial to consider all possible interactions, including trait
52+
implementations, that may allow users to bypass the invariants. For example,
53+
if the `Username` type implements the `DerefMut` trait, users can modify the
54+
underlying string directly, bypassing the validation checks in `new`.
5655

5756
- Type-level invariants have second-order benefits.\
58-
The input is validated once, at the boundary, and the rest of the program can rely
59-
on the invariants being upheld. We can avoid redundant validation and
57+
The input is validated once, at the boundary, and the rest of the program can
58+
rely on the invariants being upheld. We can avoid redundant validation and
6059
"defensive programming" checks throughout the program, reducing noise and
6160
improving performance.
6261

0 commit comments

Comments
 (0)