protobuf/reflect/repeated/
drain_iter.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::reflect::runtime_types::RuntimeTypeTrait;
use crate::reflect::ProtobufValue;
use crate::reflect::ReflectValueBox;

pub(crate) struct ReflectRepeatedDrainIter<'a> {
    imp: Box<dyn Iterator<Item = ReflectValueBox> + 'a>,
}

impl<'a> ReflectRepeatedDrainIter<'a> {
    pub(crate) fn new(
        imp: impl Iterator<Item = ReflectValueBox> + 'a,
    ) -> ReflectRepeatedDrainIter<'a> {
        ReflectRepeatedDrainIter { imp: Box::new(imp) }
    }

    pub(crate) fn new_vec<V: ProtobufValue>(v: &'a mut Vec<V>) -> ReflectRepeatedDrainIter<'a> {
        ReflectRepeatedDrainIter::new(v.drain(..).map(V::RuntimeType::into_value_box))
    }
}

impl<'a> Iterator for ReflectRepeatedDrainIter<'a> {
    type Item = ReflectValueBox;

    fn next(&mut self) -> Option<Self::Item> {
        self.imp.next()
    }
}