rusthound_ce/storage/
mod.rs

1pub mod buffer;
2pub mod iter;
3use std::error::Error;
4
5pub use buffer::{BincodeObjectBuffer, Storage};
6
7use crate::ldap::LdapSearchEntry;
8pub use iter::DiskStorageReader;
9
10pub type DiskStorage = BincodeObjectBuffer<LdapSearchEntry>;
11
12/// Used to iterate over LDAP search entries.
13///
14// trait is required because BincodeFileIterator will return a Result(LdapSearchEntry, Box<dyn Error>)
15// without this trait the caller has to convert like `self.into_iter().map(Ok)`
16pub trait EntrySource {
17    type Iter: Iterator<Item = Result<LdapSearchEntry, Box<dyn Error>>>;
18    fn into_entry_iter(self) -> Self::Iter;
19}
20
21// For reading from cache
22impl EntrySource for DiskStorageReader<LdapSearchEntry> {
23    type Iter = Self;
24
25    fn into_entry_iter(self) -> Self::Iter {
26        self
27    }
28}
29
30// For reading from memory
31impl EntrySource for Vec<LdapSearchEntry> {
32    type Iter = std::iter::Map<
33        std::vec::IntoIter<LdapSearchEntry>,
34        fn(LdapSearchEntry) -> Result<LdapSearchEntry, Box<dyn Error>>,
35    >;
36
37    fn into_entry_iter(self) -> Self::Iter {
38        self.into_iter().map(Ok)
39    }
40}