Skip to content

Commit 26cfe2b

Browse files
tall-vasegribozavr
andauthored
Apply suggestions from code review
Co-authored-by: Dmitri Gribenko <[email protected]>
1 parent 2d3f915 commit 26cfe2b

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/idiomatic/leveraging-the-type-system/borrow-checker-invariants.md

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

55
# Using the Borrow checker to enforce Invariants
66

7-
The logic of the borrow checker, while tied to "memory ownership", can be
8-
abstracted away from this central use case to model other problems and prevent
9-
API misuse.
7+
The borrow checker, while added to enforce memory ownership, can be
8+
leveraged model other problems and prevent API misuse.
109

1110
```rust,editable
1211
// Doors can be open or closed, and you need the right key to lock or unlock
@@ -66,9 +65,7 @@ fn main() {
6665
wrong key the door is still closed (here represented as an error) and the key
6766
persists regardless.
6867

69-
- The rules of the borrow checker exist to prevent developers from accessing,
70-
changing, and holding onto data in memory in unpredictable ways without being
71-
so restrictive that it would prevent _writing software_. The underlying
68+
- The rules of the borrow checker exist to prevent memory safety bugs. However, the underlying
7269
logical system does not "know" what memory is. All it does is enforce a
7370
specific set of rules of how different operations affect what later operations
7471
are possible.

src/idiomatic/leveraging-the-type-system/borrow-checker-invariants/single-use-values.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232

3333
<details>
3434

35-
- What if we want to be able to guarantee that a value can only be used once?
35+
- Problem: How can we guarantee a value is used only once?
3636

3737
- Motivation: A nonce is a piece of random, unique data used in cryptographic
3838
protocols to prevent replay attacks.
@@ -46,8 +46,7 @@ fn main() {
4646
- Rust has an obvious tool for "Once you use this, you can't use it anymore":
4747
Using a value as an _owned argument_.
4848

49-
- Highlight: the `encrypt` function takes references for `key` and `data` but
50-
not `nonce`
49+
- Highlight: the `encrypt` function takes `nonce` by value (an owned argument), but `key` and `data` by reference.
5150

5251
- By keeping constructors private and not implementing clone/copy for a type,
5352
making the interior type opaque (as per the newtype pattern), we can prevent

0 commit comments

Comments
 (0)