Skip to content

Commit aca1ed5

Browse files
Impl Clone for RepeatedIter
This matches std types like std::slice::Iter. PiperOrigin-RevId: 750622078
1 parent 88e11bd commit aca1ed5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

rust/repeated.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub unsafe trait ProxiedInRepeated: Proxied + SealedInternal {
356356
}
357357

358358
/// An iterator over the values inside of a [`View<Repeated<T>>`](RepeatedView).
359+
#[derive(Clone)]
359360
pub struct RepeatedIter<'msg, T> {
360361
view: RepeatedView<'msg, T>,
361362
current_index: usize,
@@ -688,8 +689,14 @@ mod tests {
688689
}
689690

690691
#[gtest]
691-
fn test_repeated_iter_into_proxied() {
692+
fn test_repeated_iter() {
692693
let r: Repeated<i32> = [0, 1, 2, 3].into_iter().into_proxied(Private);
693694
assert_that!(r.as_view(), elements_are![eq(0), eq(1), eq(2), eq(3)]);
695+
696+
let mut iter = r.as_view().into_iter();
697+
assert_that!(iter.next(), eq(Some(0)));
698+
let mut clone = iter.clone();
699+
assert_that!(clone.next(), eq(Some(1)));
700+
assert_that!(iter.next(), eq(Some(1)));
694701
}
695702
}

0 commit comments

Comments
 (0)