rill_view/flow/data/
dict.rs1use rill_protocol::flow::core::{Flow, TimedEvent};
2use rill_protocol::io::provider::StreamType;
3use serde::{Deserialize, Serialize};
4use std::collections::BTreeMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct DictState {
8 pub map: BTreeMap<String, String>,
9}
10
11#[allow(clippy::new_without_default)]
12impl DictState {
13 pub fn new() -> Self {
14 Self {
15 map: BTreeMap::new(),
16 }
17 }
18}
19
20impl Flow for DictState {
21 type Action = ();
22 type Event = DictEvent;
23
24 fn stream_type() -> StreamType {
25 StreamType::from("rillrate.data.dict.v0")
26 }
27
28 fn apply(&mut self, event: TimedEvent<Self::Event>) {
29 match event.event {
30 DictEvent::Assign { key, value } => {
31 self.map.insert(key, value);
32 }
33 DictEvent::Remove { key } => {
34 self.map.remove(&key);
35 }
36 }
37 }
38}
39
40pub type DictDelta = Vec<TimedEvent<DictEvent>>;
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub enum DictEvent {
44 Assign { key: String, value: String },
45 Remove { key: String },
46}