This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 5e7a80b
committed
Make handling of
The current way of stepping through each comment in `Comments` is a bit
weird. There is a `Vec<Comments>` and a `current` index, which is fine.
The `Comments::next` method clones the current comment but doesn't
advance `current`; the advancing instead happens in `print_comment`,
which is where each cloned comment is actually finally used (or not, in
some cases, if the comment fails to satisfy a predicate).
This commit makes things more iterator-like:
- `Comments::next` now advances `current` instead of `print_comment`.
- `Comments::peek` is added so you can inspect a comment and check a
predicate without consuming it.
- This requires splitting `PrintState::comments` into immutable and
mutable versions. The commit also moves the ref inside the `Option` of
the return type, to save callers from having to use `as_ref`/`as_mut`.
- It also requires adding `PrintState::peek_comment` alongside the
existing `PrintState::next_comment`. (The lifetimes in the signature
of `peek_comment` ended up more complex than I expected.)
We now have a neat separation between consuming (`next`) and
non-consuming (`peek`) uses of each comment. As well as being clearer,
this will facilitate the next commit that avoids unnecessary cloning.Comments more iterator-like.1 parent 852a78e commit 5e7a80b
2 files changed
+40
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
189 | 193 | | |
190 | | - | |
191 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
192 | 198 | | |
193 | 199 | | |
194 | 200 | | |
195 | | - | |
| 201 | + | |
196 | 202 | | |
197 | 203 | | |
198 | 204 | | |
199 | | - | |
| 205 | + | |
200 | 206 | | |
201 | 207 | | |
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
205 | 211 | | |
206 | 212 | | |
207 | | - | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
| |||
400 | 406 | | |
401 | 407 | | |
402 | 408 | | |
403 | | - | |
| 409 | + | |
| 410 | + | |
404 | 411 | | |
405 | 412 | | |
406 | 413 | | |
| |||
442 | 449 | | |
443 | 450 | | |
444 | 451 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
| 452 | + | |
| 453 | + | |
450 | 454 | | |
451 | 455 | | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
452 | 459 | | |
453 | 460 | | |
454 | 461 | | |
455 | 462 | | |
456 | | - | |
| 463 | + | |
457 | 464 | | |
458 | 465 | | |
459 | 466 | | |
| |||
517 | 524 | | |
518 | 525 | | |
519 | 526 | | |
520 | | - | |
521 | | - | |
522 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
523 | 531 | | |
524 | 532 | | |
525 | 533 | | |
526 | | - | |
| 534 | + | |
527 | 535 | | |
528 | 536 | | |
529 | 537 | | |
530 | | - | |
| 538 | + | |
531 | 539 | | |
532 | | - | |
| 540 | + | |
533 | 541 | | |
534 | 542 | | |
535 | 543 | | |
536 | 544 | | |
537 | 545 | | |
538 | 546 | | |
539 | 547 | | |
540 | | - | |
| 548 | + | |
541 | 549 | | |
542 | 550 | | |
543 | 551 | | |
544 | | - | |
| 552 | + | |
545 | 553 | | |
546 | 554 | | |
547 | 555 | | |
| |||
994 | 1002 | | |
995 | 1003 | | |
996 | 1004 | | |
997 | | - | |
998 | | - | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
999 | 1011 | | |
1000 | 1012 | | |
1001 | 1013 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| |||
0 commit comments