egui_graph_edit/
index_impls.rs1use super::*;
2
3macro_rules! impl_index_traits {
4 ($id_type:ty, $output_type:ty, $arena:ident) => {
5 impl<A, B, C> std::ops::Index<$id_type> for Graph<A, B, C> {
6 type Output = $output_type;
7
8 fn index(&self, index: $id_type) -> &Self::Output {
9 self.$arena.get(index).unwrap_or_else(|| {
10 panic!(
11 "{} index error for {:?}. Has the value been deleted?",
12 stringify!($id_type),
13 index
14 )
15 })
16 }
17 }
18
19 impl<A, B, C> std::ops::IndexMut<$id_type> for Graph<A, B, C> {
20 fn index_mut(&mut self, index: $id_type) -> &mut Self::Output {
21 self.$arena.get_mut(index).unwrap_or_else(|| {
22 panic!(
23 "{} index error for {:?}. Has the value been deleted?",
24 stringify!($id_type),
25 index
26 )
27 })
28 }
29 }
30 };
31}
32
33impl_index_traits!(NodeId, Node<A>, nodes);
34impl_index_traits!(InputId, InputParam<B, C>, inputs);
35impl_index_traits!(OutputId, OutputParam<B>, outputs);