Skip to main content

egui_graph_edit/
id_type.rs

1slotmap::new_key_type! { pub struct NodeId; }
2slotmap::new_key_type! { pub struct InputId; }
3slotmap::new_key_type! { pub struct OutputId; }
4
5#[cfg_attr(feature = "persistence", derive(serde::Serialize, serde::Deserialize))]
6#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7pub enum AnyParameterId {
8    Input(InputId),
9    Output(OutputId),
10}
11
12impl AnyParameterId {
13    pub fn assume_input(&self) -> InputId {
14        match self {
15            AnyParameterId::Input(input) => *input,
16            AnyParameterId::Output(output) => panic!("{:?} is not an InputId", output),
17        }
18    }
19    pub fn assume_output(&self) -> OutputId {
20        match self {
21            AnyParameterId::Output(output) => *output,
22            AnyParameterId::Input(input) => panic!("{:?} is not an OutputId", input),
23        }
24    }
25}
26
27impl From<OutputId> for AnyParameterId {
28    fn from(output: OutputId) -> Self {
29        Self::Output(output)
30    }
31}
32
33impl From<InputId> for AnyParameterId {
34    fn from(input: InputId) -> Self {
35        Self::Input(input)
36    }
37}