• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4354627675

pending completion
4354627675

push

github

GitHub
chore: Use `LmdbMap` and `LmdbMultimap` instead of raw database in cache (#1156)

754 of 754 new or added lines in 15 files covered. (100.0%)

29895 of 39630 relevant lines covered (75.44%)

38604.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.67
/dozer-storage/src/lmdb_database/iterator.rs
1
use std::{borrow::Cow, ops::Bound};
2

3
use lmdb::Cursor;
4

5
use crate::{errors::StorageError, Decode, Encode, Encoded};
6

7
use super::raw_iterator::RawIterator;
8

9
pub struct KeyIterator<'txn, C: Cursor<'txn>, K: ?Sized> {
10
    inner: RawIterator<'txn, C>,
11
    _key: std::marker::PhantomData<*const K>,
12
}
13

14
fn encode_bound<K: Encode + ?Sized>(key: Bound<&K>) -> Result<Bound<Encoded>, StorageError> {
4,629✔
15
    match key {
4,629✔
16
        Bound::Included(key) => Ok(Bound::Included(key.encode()?)),
1,657✔
17
        Bound::Excluded(key) => Ok(Bound::Excluded(key.encode()?)),
1,908✔
18
        Bound::Unbounded => Ok(Bound::Unbounded),
1,064✔
19
    }
20
}
4,629✔
21

22
fn bound_as_ref<'a>(bound: &'a Bound<Encoded<'a>>) -> Bound<&'a [u8]> {
7,596✔
23
    match bound {
7,596✔
24
        Bound::Included(key) => Bound::Included(key.as_ref()),
2,673✔
25
        Bound::Excluded(key) => Bound::Excluded(key.as_ref()),
2,952✔
26
        Bound::Unbounded => Bound::Unbounded,
1,971✔
27
    }
28
}
7,596✔
29

30
impl<'txn, C: Cursor<'txn>, K: Encode + ?Sized> KeyIterator<'txn, C, K> {
31
    pub fn new(cursor: C, starting_key: Bound<&K>, ascending: bool) -> Result<Self, StorageError> {
154✔
32
        let starting_key = encode_bound(starting_key)?;
154✔
33
        let inner = RawIterator::new(cursor, bound_as_ref(&starting_key), ascending)?;
154✔
34
        Ok(Self {
154✔
35
            inner,
154✔
36
            _key: std::marker::PhantomData,
154✔
37
        })
154✔
38
    }
154✔
39
}
40

41
fn decode_key<'a, K: Decode + 'a + ?Sized>(key: &'a [u8]) -> Result<Cow<'a, K>, StorageError> {
2,377,702✔
42
    let key = K::decode(key).map_err(|e| StorageError::DeserializationError {
2,377,702✔
43
        typ: "Iterator::K",
×
44
        reason: Box::new(e),
×
45
    })?;
2,377,702✔
46
    Ok(key)
2,377,702✔
47
}
2,377,702✔
48

49
impl<'txn, C: Cursor<'txn>, K: Decode + 'txn + ?Sized> std::iter::Iterator
50
    for KeyIterator<'txn, C, K>
51
{
52
    type Item = Result<Cow<'txn, K>, StorageError>;
53

54
    fn next(&mut self) -> Option<Self::Item> {
55
        match self.inner.next()? {
58,262✔
56
            Ok((key, _)) => Some(decode_key(key)),
58,198✔
57
            Err(e) => Some(Err(e.into())),
×
58
        }
59
    }
58,262✔
60
}
61

62
pub struct ValueIterator<'txn, C: Cursor<'txn>, V: ?Sized> {
63
    inner: RawIterator<'txn, C>,
64
    _value: std::marker::PhantomData<*const V>,
65
}
66

67
impl<'txn, C: Cursor<'txn>, V: ?Sized> ValueIterator<'txn, C, V> {
68
    pub fn new<K: Encode + ?Sized>(
×
69
        cursor: C,
×
70
        starting_key: Bound<&K>,
×
71
        ascending: bool,
×
72
    ) -> Result<Self, StorageError> {
×
73
        let starting_key = encode_bound(starting_key)?;
×
74
        let inner = RawIterator::new(cursor, bound_as_ref(&starting_key), ascending)?;
×
75
        Ok(Self {
×
76
            inner,
×
77
            _value: std::marker::PhantomData,
×
78
        })
×
79
    }
×
80
}
81

82
fn decode_value<'a, V: Decode + 'a + ?Sized>(value: &'a [u8]) -> Result<Cow<'a, V>, StorageError> {
2,319,504✔
83
    let value = V::decode(value).map_err(|e| StorageError::DeserializationError {
2,319,504✔
84
        typ: "Iterator::V",
×
85
        reason: Box::new(e),
×
86
    })?;
2,319,504✔
87
    Ok(value)
2,319,504✔
88
}
2,319,504✔
89

90
impl<'txn, C: Cursor<'txn>, V: Decode + 'txn + ?Sized> std::iter::Iterator
91
    for ValueIterator<'txn, C, V>
92
{
93
    type Item = Result<Cow<'txn, V>, StorageError>;
94

95
    fn next(&mut self) -> Option<Self::Item> {
96
        match self.inner.next()? {
×
97
            Ok((_, value)) => Some(decode_value(value)),
×
98
            Err(e) => Some(Err(e.into())),
×
99
        }
100
    }
×
101
}
102

103
pub struct Iterator<'txn, C: Cursor<'txn>, K: ?Sized, V: ?Sized> {
104
    inner: RawIterator<'txn, C>,
105
    _key: std::marker::PhantomData<*const K>,
106
    _value: std::marker::PhantomData<*const V>,
107
}
108

109
impl<'txn, C: Cursor<'txn>, K: Encode + ?Sized, V: ?Sized> Iterator<'txn, C, K, V> {
110
    pub fn new(cursor: C, starting_key: Bound<&K>, ascending: bool) -> Result<Self, StorageError> {
4,475✔
111
        let starting_key = encode_bound(starting_key)?;
4,475✔
112
        let inner = RawIterator::new(cursor, bound_as_ref(&starting_key), ascending)?;
4,475✔
113
        Ok(Self {
4,475✔
114
            inner,
4,475✔
115
            _key: std::marker::PhantomData,
4,475✔
116
            _value: std::marker::PhantomData,
4,475✔
117
        })
4,475✔
118
    }
4,475✔
119
}
120

121
fn decode_key_value<'a, K: Decode + 'a + ?Sized, V: Decode + 'a + ?Sized>(
2,319,504✔
122
    key: &'a [u8],
2,319,504✔
123
    value: &'a [u8],
2,319,504✔
124
) -> Result<(Cow<'a, K>, Cow<'a, V>), StorageError> {
2,319,504✔
125
    let key = decode_key(key)?;
2,319,504✔
126
    let value = decode_value(value)?;
2,319,504✔
127
    Ok((key, value))
2,319,504✔
128
}
2,319,504✔
129

130
impl<'txn, C: Cursor<'txn>, K: Decode + 'txn + ?Sized, V: Decode + 'txn + ?Sized>
131
    std::iter::Iterator for Iterator<'txn, C, K, V>
132
{
133
    type Item = Result<(Cow<'txn, K>, Cow<'txn, V>), StorageError>;
134

135
    fn next(&mut self) -> Option<Self::Item> {
136
        match self.inner.next()? {
2,321,797✔
137
            Ok((key, value)) => Some(decode_key_value(key, value)),
2,319,504✔
138
            Err(e) => Some(Err(e.into())),
×
139
        }
140
    }
2,321,798✔
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc