rill_protocol/flow/meta/
path.rs

1use crate::flow::core::Flow;
2use crate::flow::location::Location;
3use crate::io::provider::{Description, Path, StreamType};
4use serde::{Deserialize, Serialize};
5use std::collections::BTreeMap;
6
7pub const PATHS: Location = Location::new("meta:paths");
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct PathState {
11    /// Description of the provider
12    pub description: Description,
13    #[serde(with = "vectorize")]
14    pub paths: BTreeMap<Path, Description>,
15}
16
17#[allow(clippy::new_without_default)]
18impl PathState {
19    pub fn new(description: Description) -> Self {
20        Self {
21            description,
22            paths: BTreeMap::new(),
23        }
24    }
25}
26
27impl Flow for PathState {
28    type Action = ();
29    type Event = PathEvent;
30
31    fn stream_type() -> StreamType {
32        StreamType::from("rillrate::meta::path::v0")
33    }
34
35    fn apply(&mut self, event: Self::Event) {
36        match event {
37            PathEvent::AddPath { path, description } => {
38                self.paths.insert(path, description);
39            }
40            PathEvent::RemovePath { path } => {
41                self.paths.remove(&path);
42            }
43        }
44    }
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub enum PathEvent {
49    AddPath {
50        path: Path,
51        description: Description,
52    },
53    RemovePath {
54        path: Path,
55    },
56}