add IntoProxied Repeated blanket impl for Iterators

PiperOrigin-RevId: 652555465
pull/17405/head
Derek Benson 4 months ago committed by Copybara-Service
parent cfff6e9811
commit cee9da9469
  1. 19
      rust/repeated.rs

@ -261,6 +261,19 @@ where
} }
} }
impl<'msg, T, I, U> IntoProxied<Repeated<T>> for I
where
I: Iterator<Item = U>,
T: 'msg + ProxiedInRepeated,
U: IntoProxied<T>,
{
fn into_proxied(self, _private: Private) -> Repeated<T> {
let mut repeated: Repeated<T> = Repeated::new();
repeated.as_mut().extend(self);
repeated
}
}
/// Types that can appear in a `Repeated<T>`. /// Types that can appear in a `Repeated<T>`.
/// ///
/// This trait is implemented by generated code to communicate how the proxied /// This trait is implemented by generated code to communicate how the proxied
@ -588,4 +601,10 @@ mod tests {
assert_that!(r.as_mut(), elements_are![eq(0), eq(1), eq(2), eq(3)]); assert_that!(r.as_mut(), elements_are![eq(0), eq(1), eq(2), eq(3)]);
} }
#[test]
fn test_repeated_iter_into_proxied() {
let r: Repeated<i32> = [0, 1, 2, 3].into_iter().into_proxied(Private);
assert_that!(r.as_view(), elements_are![eq(0), eq(1), eq(2), eq(3)]);
}
} }

Loading…
Cancel
Save