Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- pub struct CircuitBuilder<'a> {
- nodes: HashMap<String, Node<'a>>,
- nodes_is_no_ouput: HashMap<String, bool>,
- factory: LowBindingNodeFactory<'a>,
- }
- #[derive(Clone)]
- enum Node<'a> {
- Not(NotGate<'a>),
- Signal(SignalGate)
- }
- impl<'a> Node<'a> {
- fn add_input(&mut self, node: &'a Node) {
- match self {
- Node::Not(gate) => gate.inputs.push(node),
- _ => ()
- }
- }
- }
- #[derive(Clone)]
- struct NotGate<'a> {
- inputs: Vec<&'a Node<'a>>,
- }
- #[derive(Clone)]
- struct SignalGate;
- struct LowBindingNodeFactory<'a>(&'a str);
- impl<'a> CircuitBuilder<'a> {
- fn connect_inputs(
- &mut self,
- node_name: String,
- node_links: Vec<String>,
- ) -> Option<&'static str> {
- for node_link in node_links.iter() {
- self.nodes_is_no_ouput.insert(node_link.clone(), true);
- match self.nodes.get_mut(&node_name.clone()) {
- Some(mut_node) => mut_node.add_input(&self.nodes[&node_link.clone()]),
- None => (),
- }
- //mut_node.add_input(new_node);
- //*self.nodes.entry(&node_name.clone()).or_insert(42).add_input(&new_node);
- //self.nodes[&node_name.clone()].add_input(&new_node);
- }
- return None;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement