teo_runtime/pipeline/
pipeline.rs

1use std::fmt::{Display, Formatter};
2use itertools::Itertools;
3use serde::Serialize;
4use crate::pipeline::item::BoundedItem;
5
6#[derive(Debug, Serialize, Clone)]
7pub struct Pipeline {
8    pub items: Vec<BoundedItem>
9}
10
11impl Pipeline {
12
13    pub fn new() -> Self {
14        Self { items: vec![] }
15    }
16
17    pub fn is_empty(&self) -> bool {
18        self.items.is_empty()
19    }
20
21    pub fn len(&self) -> usize {
22        self.items.len()
23    }
24}
25
26impl Display for Pipeline {
27
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        for (index, item) in self.items.iter().enumerate() {
30            if index == 0 {
31                f.write_str("$")?;
32            } else {
33                f.write_str(".")?;
34            }
35            f.write_str(&item.path.join("."))?;
36            if !item.arguments.is_empty() {
37                f.write_str("(")?;
38                f.write_str(&item.arguments.iter().map(|(k, v)| format!("{k}: {}", v)).join(", "))?;
39                f.write_str(")")?;
40            }
41        }
42        Ok(())
43    }
44}