compris/kv/
btreemap.rs

1use super::{super::normal::*, iterator::*};
2
3use std::collections::*;
4
5//
6// KeyValuePairIteratorForBTreeMap
7//
8
9/// A [KeyValuePairIterator] for [BTreeMap].
10///
11/// It's just a simple wrapper.
12pub struct KeyValuePairIteratorForBTreeMap<'own, AnnotatedT> {
13    /// Inner.
14    pub inner: btree_map::Iter<'own, Variant<AnnotatedT>, Variant<AnnotatedT>>,
15}
16
17impl<'own, AnnotatedT> KeyValuePairIteratorForBTreeMap<'own, AnnotatedT> {
18    /// Constructor.
19    pub fn new(inner: btree_map::Iter<'own, Variant<AnnotatedT>, Variant<AnnotatedT>>) -> Self {
20        Self { inner }
21    }
22
23    /// Constructor.
24    pub fn new_for(map: &'own BTreeMap<Variant<AnnotatedT>, Variant<AnnotatedT>>) -> Self {
25        Self::new(map.into_iter())
26    }
27}
28
29impl<'own, AnnotatedT> KeyValuePairIterator<AnnotatedT> for KeyValuePairIteratorForBTreeMap<'own, AnnotatedT> {
30    fn next(
31        &mut self,
32    ) -> Result<
33        Option<(&'own Variant<AnnotatedT>, &'own Variant<AnnotatedT>)>,
34        (MalformedError<AnnotatedT>, &Variant<AnnotatedT>),
35    > {
36        Ok(self.inner.next())
37    }
38}
39
40//
41// KeyValuePairIteratorForBTreeMap
42//
43
44/// An [IntoKeyValuePairIterator] for [BTreeMap].
45///
46/// It's just a simple wrapper.
47pub struct IntoKeyValuePairIteratorForBTreeMap<AnnotatedT> {
48    /// Inner.
49    pub inner: btree_map::IntoIter<Variant<AnnotatedT>, Variant<AnnotatedT>>,
50}
51
52impl<AnnotatedT> IntoKeyValuePairIteratorForBTreeMap<AnnotatedT> {
53    /// Constructor.
54    pub fn new(inner: btree_map::IntoIter<Variant<AnnotatedT>, Variant<AnnotatedT>>) -> Self {
55        Self { inner }
56    }
57
58    /// Constructor.
59    pub fn new_for(map: BTreeMap<Variant<AnnotatedT>, Variant<AnnotatedT>>) -> Self {
60        Self::new(map.into_iter())
61    }
62}
63
64impl<AnnotatedT> IntoKeyValuePairIterator<AnnotatedT> for IntoKeyValuePairIteratorForBTreeMap<AnnotatedT> {
65    fn next(
66        &mut self,
67    ) -> Result<Option<(Variant<AnnotatedT>, Variant<AnnotatedT>)>, (MalformedError<AnnotatedT>, Variant<AnnotatedT>)>
68    {
69        Ok(self.inner.next())
70    }
71}