composable_indexes_core/
index.rs1use crate::collection::{Insert, Key, Remove, Update};
2use std::collections::HashMap;
3
4pub trait Index<'t, In> {
5 type Query<Out>
6 where
7 Self: 't,
8 Out: 't;
9
10 fn insert(&mut self, op: &Insert<In>);
11 fn remove(&mut self, op: &Remove<In>);
12
13 fn update(&mut self, op: &Update<In>) {
14 self.remove(&Remove {
15 key: op.key,
16 existing: op.existing,
17 });
18 self.insert(&Insert {
19 key: op.key,
20 new: op.new,
21 });
22 }
23
24 fn query<Out>(&'t self, env: QueryEnv<'t, Out>) -> Self::Query<Out>;
25}
26
27pub struct QueryEnv<'t, T> {
28 pub data: &'t HashMap<Key, T>,
29}
30
31impl<'t, T> Clone for QueryEnv<'t, T> {
32 fn clone(&self) -> Self {
33 QueryEnv { data: self.data }
34 }
35}