From cee9da9469c0cd4c94a9891e5c81fd94257ae2ed Mon Sep 17 00:00:00 2001 From: Derek Benson Date: Mon, 15 Jul 2024 11:59:14 -0700 Subject: [PATCH] add IntoProxied Repeated blanket impl for Iterators PiperOrigin-RevId: 652555465 --- rust/repeated.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rust/repeated.rs b/rust/repeated.rs index 5d455922f6..4044b8c67e 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -261,6 +261,19 @@ where } } +impl<'msg, T, I, U> IntoProxied> for I +where + I: Iterator, + T: 'msg + ProxiedInRepeated, + U: IntoProxied, +{ + fn into_proxied(self, _private: Private) -> Repeated { + let mut repeated: Repeated = Repeated::new(); + repeated.as_mut().extend(self); + repeated + } +} + /// Types that can appear in a `Repeated`. /// /// 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)]); } + + #[test] + fn test_repeated_iter_into_proxied() { + let r: Repeated = [0, 1, 2, 3].into_iter().into_proxied(Private); + assert_that!(r.as_view(), elements_are![eq(0), eq(1), eq(2), eq(3)]); + } }