infinitree/fields/
strategy.rs

1//! Serialization strategies for index fields
2
3/// Allows decoupling a storage strategy for index fields from the
4/// in-memory representation.
5pub trait Strategy<T: Send + Sync>: Send + Sync {
6    /// Instantiate a new `Strategy`.
7    fn for_field(field: &T) -> Self
8    where
9        Self: Sized;
10}
11
12/// Stores values in the object pool, while keeping
13/// keys in the index
14pub struct SparseField<Field> {
15    pub field: Field,
16}
17
18impl<T: Send + Sync + Clone> Strategy<T> for SparseField<T> {
19    #[inline(always)]
20    fn for_field(field: &'_ T) -> Self {
21        SparseField {
22            field: field.clone(),
23        }
24    }
25}
26
27/// Store the entire field in the index
28pub struct LocalField<Field> {
29    pub field: Field,
30}
31impl<T: Send + Sync + Clone> Strategy<T> for LocalField<T> {
32    #[inline(always)]
33    fn for_field(field: &T) -> Self {
34        LocalField {
35            field: field.clone(),
36        }
37    }
38}