Skip to content

Commit bc3dbfa

Browse files
About impl Clone
1 parent 7e5e434 commit bc3dbfa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ impl<I: fmt::Debug, F> fmt::Debug for Name4<I, F> {
131131
```
132132
</details>
133133

134+
### When/How to implement [`Clone`](https://doc.rust-lang.org/std/clone/trait.Clone.html)
135+
All our iterators should implement `Clone` when possible.
136+
137+
Note that a mutable reference is never clonable so `struct Name<'a, I: 'a> { iter: &'a mut I }` can not implement `Clone`.
138+
139+
Derive `Clone` on a generic struct adds the bound `Clone` on each generic parameter.
140+
It might be an issue in which case you should manually implement it with our helper macro `clone_fields` (it defines the `clone` function calling `clone` on each field) and be careful about the bounds.
141+
134142
### When to implement [`std::iter::FusedIterator`](https://doc.rust-lang.org/std/iter/trait.FusedIterator.html)
135143
This trait should be implemented _by all iterators that always return `None` after returning `None` once_, because it allows to optimize `Iterator::fuse()`.
136144

0 commit comments

Comments
 (0)