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