Skip to main content

capillary/
lib.rs

1//! capillary introduces a [`Dictionary`] data structure. It's used for cases where search by
2//! partial key is needed.
3//!
4//! In particular useful when performing some kind of find and replace in some data.
5//!
6//! i.e. one might want to perform find and replace in a string. With `capillary::Dictionary` it is
7//! possible to keep starting a search, and `Dictionary` will be in __default__ state until some
8//! character is part of a valid key. As long as the following characters are part of a valid key,
9//! the state of `Dictionary` will be set to some part of the `key` towards the `value`. It is then
10//! possible to test if some `value` is reached, and return it as soon as it gets hit.
11
12mod dict;
13
14pub use dict::*;
15
16/// Error indicating that some key part lead to invalid [`Dictionary`] state, thus resetting the
17/// [`Dictionary`] to the default state.
18pub struct InvalidKeyPartErr;
19
20impl<KeyParts, K, V> FromIterator<(KeyParts, V)> for Dictionary<K, V>
21where
22    KeyParts: IntoIterator<Item = K>,
23    K: PartialEq,
24{
25    fn from_iter<I: IntoIterator<Item = (KeyParts, V)>>(iter: I) -> Self {
26        let mut dictionary = Self::default();
27
28        for (key, value) in iter {
29            dictionary.insert(key, value);
30        }
31
32        dictionary
33    }
34}