minerva 0.2.0

Causal ordering for distributed systems
extern crate alloc;

use super::super::DotStore;
use super::DotMap;

/// A borrowing iterator over a [`DotMap`]'s live `(key, store)` entries in
/// ascending key order (the read side of the composition shape).
pub struct DotMapIter<'a, K, S> {
    /// The underlying canonical-map walk.
    inner: alloc::collections::btree_map::Iter<'a, K, S>,
}

impl<'a, K, S> DotMapIter<'a, K, S> {
    pub(super) const fn new(inner: alloc::collections::btree_map::Iter<'a, K, S>) -> Self {
        Self { inner }
    }
}

impl<'a, K, S> Iterator for DotMapIter<'a, K, S> {
    type Item = (&'a K, &'a S);

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

impl<'a, K: Ord + Clone, S: DotStore> IntoIterator for &'a DotMap<K, S> {
    type Item = (&'a K, &'a S);
    type IntoIter = DotMapIter<'a, K, S>;

    fn into_iter(self) -> Self::IntoIter {
        self.iter()
    }
}