Skip to content

Commit a6d22fd

Browse files
committed
Merge pull request rust-lang#237 from aturon/ownership-variants-followup
Revision: change iter_move to into_iter
2 parents c0c6bc5 + bfd18a8 commit a6d22fd

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

active/0052-ownership-variants.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ If `foo` uses/produces an immutable borrow by default, use:
4545
* The `_mut` suffix (e.g. `foo_mut`) for the mutably borrowed variant.
4646
* The `_move` suffix (e.g. `foo_move`) for the owned variant.
4747

48-
A consequence is that the iterator methods become: `iter`, `iter_mut`,
49-
and `iter_move`.
48+
However, in the case of iterators, the moving variant can also be
49+
understood as an `into` conversion, `into_iter`, and `for x in v.into_iter()`
50+
reads arguably better than `for x in v.iter_move()`, so the convention is
51+
`into_iter`.
5052

5153
**NOTE**: This convention covers only the *method* names for
5254
iterators, not the names of the iterator types. That will be the
@@ -142,15 +144,3 @@ Another option would be `val` or `value` instead of `owned`. This
142144
suggestion plays into the "by reference" and "by value" distinction,
143145
and so is even more congruent with `ref` than `move` is. On the other
144146
hand, it's less clear/evocative than either `move` or `owned`.
145-
146-
## `into_iter`
147-
148-
For the case of iteration, at least, it would make some sense to
149-
signal ownership transfer by treating the owned version as a
150-
conversion, `into_iter`. The main downside is that it would go against
151-
the general convention for ownership variants (and cannot be used as
152-
the general convention, because not all cases can be seen as
153-
conversions).
154-
155-
Moreover, it's strange to see just the owning variant as a conversion
156-
-- why not `as_iter`, `as_iter_mut`, and `into_iter`?

0 commit comments

Comments
 (0)