flarrow_layout/
node.rs

1use std::collections::HashSet;
2
3use uuid::Uuid;
4
5use crate::prelude::*;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct NodeID(pub Uuid);
9
10impl Default for NodeID {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl NodeID {
17    pub fn new() -> Self {
18        NodeID(Uuid::new_v4())
19    }
20
21    pub fn input(&self, input: impl Into<String>) -> InputID {
22        InputID(Uuid::new_v3(&self.0, input.into().as_bytes()))
23    }
24
25    pub fn output(&self, output: impl Into<String>) -> OutputID {
26        OutputID(Uuid::new_v3(&self.0, output.into().as_bytes()))
27    }
28}
29
30pub struct NodeIO {
31    pub id: NodeID,
32
33    pub inputs: HashSet<InputID>,
34    pub outputs: HashSet<OutputID>,
35}
36
37impl Default for NodeIO {
38    fn default() -> Self {
39        Self::new()
40    }
41}
42
43impl NodeIO {
44    pub fn new() -> Self {
45        Self {
46            id: NodeID::new(),
47            inputs: HashSet::new(),
48            outputs: HashSet::new(),
49        }
50    }
51
52    pub fn open_input(&mut self, input: impl Into<String>) -> InputID {
53        let input_id = self.id.input(input);
54
55        self.inputs.insert(input_id);
56
57        input_id
58    }
59
60    pub fn open_output(&mut self, output: impl Into<String>) -> OutputID {
61        let output_id = self.id.output(output);
62
63        self.outputs.insert(output_id);
64
65        output_id
66    }
67}