Implement ExactSizeIterator and FusedIterator for repeated fields.
PiperOrigin-RevId: 591306340
diff --git a/rust/repeated.rs b/rust/repeated.rs
index 22d6fb9..2753fce 100644
--- a/rust/repeated.rs
+++ b/rust/repeated.rs
@@ -7,6 +7,7 @@
use std::fmt::{self, Debug};
use std::iter;
+use std::iter::FusedIterator;
/// Repeated scalar fields are implemented around the runtime-specific
/// `RepeatedField` struct. `RepeatedField` stores an opaque pointer to the
/// runtime-specific representation of a repeated scalar (`upb_Array*` on upb,
@@ -367,6 +368,14 @@
}
}
+impl<'msg, T: ?Sized + ProxiedInRepeated> ExactSizeIterator for RepeatedIter<'msg, T> {
+ fn len(&self) -> usize {
+ self.view.len()
+ }
+}
+
+impl<'msg, T: ?Sized + ProxiedInRepeated> FusedIterator for RepeatedIter<'msg, T> {}
+
impl<'msg, T> iter::IntoIterator for RepeatedView<'msg, T>
where
T: ProxiedInRepeated + ?Sized + 'msg,