instruction_serialiser/
xor_node.rs

1use std::collections::HashMap;
2use std::ops::{BitXor, BitXorAssign};
3use crate::calculation_error::CalculationError;
4use crate::generic_node::GenericNode;
5use crate::instruction_serialiser::{LogicalResultNodeWrapper, XorNode};
6use crate::instruction_serialiser::logical_result_node_wrapper::Node;
7use crate::logical_type::LogicalType;
8use crate::node_wrapper::NodeWrapper;
9use crate::parameter::Parameter;
10
11impl GenericNode<LogicalType> for XorNode {
12    fn calculate(&self, parameters: &HashMap<&str, Parameter>) -> Result<LogicalType, CalculationError> {
13        let left_node = self.left_child.as_ref().ok_or(
14            CalculationError::new("The left child of a xor node must be present to perform a calculation")
15        )?;
16        let right_node = self.right_child.as_ref().ok_or(
17            CalculationError::new("The right child of a xor node must be present to perform a calculation")
18        )?;
19        Ok(left_node.calculate_wrapped_nodes(parameters)? != right_node.calculate_wrapped_nodes(parameters)?)
20    }
21}
22
23type Lrnw = LogicalResultNodeWrapper;
24
25impl BitXor for Lrnw {
26    type Output = Self;
27
28    fn bitxor(self, node: Self) -> Self::Output {
29        Self{
30            node: Some(
31                Node::XorNode(
32                    Box::new(
33                        XorNode{
34                            left_child: Some(Box::new(self)),
35                            right_child: Some(Box::new(node))
36                        }
37                    )
38                )
39            )
40        }
41    }
42}
43
44impl BitXorAssign for Lrnw {
45    fn bitxor_assign(&mut self, node: Self) {
46        *self = self.clone().bitxor(node);
47    }
48}