logic_mesh/base/block/
props.rs1use uuid::Uuid;
8
9use crate::base::{input::Input, link::Link, output::Output};
10
11use super::{desc::BlockDesc, BlockState};
12
13pub trait BlockProps {
16 type Reader;
19 type Writer: Clone;
22
23 fn id(&self) -> &Uuid;
25
26 fn name(&self) -> &str;
28
29 fn desc(&self) -> &'static BlockDesc;
31
32 fn state(&self) -> BlockState;
34
35 fn set_state(&mut self, state: BlockState) -> BlockState;
37
38 fn inputs(&self) -> Vec<&dyn Input<Reader = Self::Reader, Writer = Self::Writer>>;
40
41 fn get_input(
43 &self,
44 name: &str,
45 ) -> Option<&dyn Input<Reader = Self::Reader, Writer = Self::Writer>> {
46 self.inputs().iter().find(|i| i.name() == name).cloned()
47 }
48
49 fn get_input_mut(
51 &mut self,
52 name: &str,
53 ) -> Option<&mut dyn Input<Reader = Self::Reader, Writer = Self::Writer>> {
54 self.inputs_mut().into_iter().find(|i| i.name() == name)
55 }
56
57 fn inputs_mut(&mut self) -> Vec<&mut dyn Input<Reader = Self::Reader, Writer = Self::Writer>>;
59
60 fn outputs(&self) -> Vec<&dyn Output<Writer = Self::Writer>>;
62
63 fn get_output(&self, name: &str) -> Option<&dyn Output<Writer = Self::Writer>> {
65 self.outputs().iter().find(|i| i.name() == name).cloned()
66 }
67
68 fn get_output_mut(&mut self, name: &str) -> Option<&mut dyn Output<Writer = Self::Writer>> {
70 self.outputs_mut().into_iter().find(|i| i.name() == name)
71 }
72
73 fn outputs_mut(&mut self) -> Vec<&mut dyn Output<Writer = Self::Writer>>;
75
76 fn links(&self) -> Vec<(&str, Vec<&dyn crate::base::link::Link>)>;
78
79 fn remove_link(&mut self, link: &dyn Link) {
81 self.remove_link_by_id(link.id())
82 }
83
84 fn remove_link_by_id(&mut self, link_id: &Uuid);
86
87 fn remove_all_links(&mut self);
89}