protobuf/reflect/repeated/
drain_iter.rs

1use crate::reflect::runtime_types::RuntimeTypeTrait;
2use crate::reflect::ProtobufValue;
3use crate::reflect::ReflectValueBox;
4
5pub(crate) struct ReflectRepeatedDrainIter<'a> {
6    imp: Box<dyn Iterator<Item = ReflectValueBox> + 'a>,
7}
8
9impl<'a> ReflectRepeatedDrainIter<'a> {
10    pub(crate) fn new(
11        imp: impl Iterator<Item = ReflectValueBox> + 'a,
12    ) -> ReflectRepeatedDrainIter<'a> {
13        ReflectRepeatedDrainIter { imp: Box::new(imp) }
14    }
15
16    pub(crate) fn new_vec<V: ProtobufValue>(v: &'a mut Vec<V>) -> ReflectRepeatedDrainIter<'a> {
17        ReflectRepeatedDrainIter::new(v.drain(..).map(V::RuntimeType::into_value_box))
18    }
19}
20
21impl<'a> Iterator for ReflectRepeatedDrainIter<'a> {
22    type Item = ReflectValueBox;
23
24    fn next(&mut self) -> Option<Self::Item> {
25        self.imp.next()
26    }
27}